Using multiple textfields or the paragraphs module the editor keeps duplicating on each ajax request.

Also changes can only be made to the last of the fields. When you save the node the changes disappear from the previous fields.

Comments

Kopin created an issue. See original summary.

kopin’s picture

Title: Bugs with multiple textfields » Support multiple textfields
Status: Needs work » Needs review
StatusFileSize
new1.22 KB

I am adding a patch that supports multiple fields. This will also work with the paragraphs module.
I am checking if the editor is already attached before calling the method and added forceSync method to the simpleMDE.

I also attached jQuery into the editor.behaviour

ademarco’s picture

Thank you so much for the patch Kopin!

  1. +++ b/js/drupal.simplemde.js
    @@ -24,10 +24,16 @@
    +      var $textfield = $(element);
    

    I would like to keep the module not dependent from jQuery as much as possible, could we perform class checking using simple vanilla JS?

  2. +++ b/js/drupal.simplemde.js
    @@ -24,10 +24,16 @@
    +      if(!$textfield.hasClass('loaded')) {
    

    We should namespace this class in order to avoid conflicts, shall we try something like "simplemce-processed"?

  3. +++ b/js/drupal.simplemde.js
    @@ -56,9 +62,8 @@
    +})(Drupal, SimpleMDE, jQuery);
    

    jQuery should be added as a library dependency too but, as said above, I'd rather not use it unless really necessary.

ademarco’s picture

Status: Needs review » Needs work
kopin’s picture

Sure we can do that. I'm just thinking since jQuery is a dependency for Drupal why not make use of it?
CKEditor does for ex. It's not like we are loading en extra library, it's already there.
What do you think?

ademarco’s picture

In Drupal 8 jQuery is not loaded by default like in Drupal 7, so I think we should remove it.

kopin’s picture

StatusFileSize
new1020 bytes

Adding new patch without jQuery and with better Classname as you requested :)

kopin’s picture

Status: Needs work » Needs review

  • ademarco committed 874d3a4 on 8.x-1.x
    Issue #2820398 by Kopin: Support multiple textfields
    
ademarco’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.