Okay, I do see where the back-end implementation for this lies... it's
in the guts of the doctrine (and presumably Propel) forms support
classes.

I still haven't figured out how to use it, though, and the 'checkbox
to delete' interface doesn't make sense to me. What does make sense to
me is picking a new file if you want to replace the existing one,
otherwise leaving it alone. That's probably because in my application
the file isn't optional. The checkbox would make more sense if the
file were not mandatory.

In the end I wound up doing this, which works well:

IN THE FORM CLASS

    $this->setValidator('file', new sfValidatorFile(
      array("mime_types" => array("image/jpeg"), "required" =>
        (!$this->getObject())),
      array("mime_types" => "Sorry, only JPEG format images are accepted.",
        "required" => "You must select a JPEG-format file to upload
with the \"Browse\" button.")));

Note that 'required' is set differently depending on whether the
object already exists.

IN THE ACTION

      if ($this->form->isValid())
      {
        $file = $this->form->getValue('file');
        // The base implementation for saving files gets confused when
        // $file is not set, a situation that our code tolerates as useful
        // because if you're updating a record containing an image you
        // often don't need to submit a new one.
        unset($this->form['file']);
        $this->form->save();
        $object = $this->form->getObject();
        $slug = $object->getSlug();
        if ($file)
        {
          $file->save('where_i_want_it');
        }
      }

This gives me the behavior I want, which I suspect is a common desire:
there has to be a file, but you don't have to replace it every time
you edit.

I think it's problematic that part of the implementation of the
sfWidgetFormFileInputEditable widget is in the core form classes. That
means that similar capabilities can't be implemented by third-party
plugins easily. Behaviors for forms could help with that. Right now a
third party plugin would have to direct the programmer to add a static
method call to a tools class from their own updateObject() or doSave()
method.

-
Tom Boutell

www.punkave.com
www.boutell.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/symfony-devs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to