unclecheese / silverstripe-dropzone

46 stars 78 forks source link

Editing Image fields after upload #71

Open sanderha opened 7 years ago

sanderha commented 7 years ago

What would be the best way to give a user the ability to edit the Title field on Image, after it has been uploaded?

I've got a use case where users upload images in a form, and then be able to set a caption for each image. Then the form is submitted.

Not sure if this module out of the box can easily let me build such functionality.

unclecheese commented 7 years ago

Usually the way you do this is by wrapping the file in a DataObject.

class MyFileDataObject extends DataObject
{
  private static $db = ['Caption' => 'Varchar'];

  private static $has_one = ['File' => 'File'];

  public function getCMSFields()
  {
    $fields = FieldList::create(TabSet::create('Root'));
    $fields->addFieldsToTab('Root.Main', [
      TextField::create('Caption'),
      FileAttachmentField::create('File')
    ]);

    return $fields;
}

Then just manage these objects with a GridField.

sanderha commented 7 years ago

Indeed, but I'm using it through the frontend .. Currently I use some ajax after upload of the images to load some textfields in for each image.. Just seems pretty crappy.

satrun77 commented 7 years ago

I'm working on a project that requires this feature. I have managed to get it working with a bit of work.

  $upload =  new FileAttachmentField('name');
  $upload->setPreviewTemplate('CustomPreviewTemplate');