froala / KMSFroalaEditorBundle

Symfony bundle for Froala WYSIWYG HTML Rich Text Editor.
https://froala.com/wysiwyg-editor
105 stars 33 forks source link

How to handle Images/Files deletion via events ? #67

Closed L0kidor closed 5 years ago

L0kidor commented 6 years ago

Hi, i'm trying to use the remove image/file function when a user delete it from the editor.

It seems that events aren't handled identically in KMS/froala than in other classic versions.

The docs don't mention it, but I found this issue #43 wich is talking about event handling.

I tried to define a JS function (called deleteImage) wich make the AJAX request and call it from event handler

->add('content', FroalaEditorType::class, array('events' => array('image.removed' => 'deleteImage')) )

But it seems that the function isn't called (my alert('test') isn't displayed)

function deleteImage(e, editor, $img) {
    alert('test');
    $.ajax({
      // Request method.
      method: "POST",
      // Request URL.
      url: '/admin/imageDelete',
      // Request params.
      data: {
        src: $img.attr('src')
      }
    })
    .done (function (data) {
      console.log ('image was deleted');
    })
    .fail (function () {
      console.log ('image delete problem');
    })
}

Can't find any Symfony specific doc about this. It don't seems to be the right way to achieve this, can anyone help ?

Parashuram-Sram commented 5 years ago

@L0kidor can you please try naming the event as "froalaEditor.image.removed" ? It has worked for me.

L0kidor commented 5 years ago

Hi, gonna try as soon as possible. Thx