Ckeditor update textarea

后端 未结 10 1603
抹茶落季
抹茶落季 2020-12-01 03:10

I am trying to get the ckeditor working. Obviously it doesn\'t make use of the textarea so on submit the form doesn\'t submit the text in the editor. Beceause I make use of

相关标签:
10条回答
  • 2020-12-01 03:13

    Combination of all of the above answers into one.

    Create a new custom.js file and add this:

    CKEDITOR.on('instanceReady', function(){
      $.each( CKEDITOR.instances, function(instance) {
    
        CKEDITOR.instances[instance].on("instanceReady", function() {
          this.document.on("keyup", CK_jQ);
          this.document.on("paste", CK_jQ);
          this.document.on("keypress", CK_jQ);
          this.document.on("blur", CK_jQ);
          this.document.on("change", CK_jQ);
        });
      });
    
    });
    
    function CK_jQ() {
      for ( var instance in CKEDITOR.instances ) { CKEDITOR.instances[instance].updateElement(); }
    }
    

    You don't have to worry about the name of the textarea, just add a class ckeditor in the textarea, the above and you are done.

    0 讨论(0)
  • 2020-12-01 03:21

    ADD Function JavaScript for Update

    function CKupdate() {
      for (instance in CKEDITOR.instances)
        CKEDITOR.instances[instance].updateElement();
    }
    

    It's work. Cool

    0 讨论(0)
  • 2020-12-01 03:23

    Just Add

    CKEDITOR.instances.textAreaClientId.on('blur', function(){CKEDITOR.instances. textAreaClientId.updateElement();});
    

    where textAreaClientId is your instance name

    Regards

    0 讨论(0)
  • 2020-12-01 03:24

    I just increase that to the response of T.J. and worked for me:

    $("form").on("submit", function(e){
        $('textarea.ckeditor').each(function () {
           var $textarea = $(this);
           $textarea.val(CKEDITOR.instances[$textarea.attr('name')].getData());
        });
    });
    
    0 讨论(0)
  • 2020-12-01 03:25

    All above answer are focusing on how to fix this error but I want to take the answer on what cause me this error

    I had a

    <textarea class="ckeditor" rows="6" name="Cms[description]"></textarea>
    

    changed to

    <textarea class="ckedit" rows="6" name="Cms[description]"></textarea>
    

    I changed class attribute value to anything other than ckeditor and boom error gone.

    Hope that help

    0 讨论(0)
  • 2020-12-01 03:30

    have you figured it out?

    I'm using CKEditor version 3.6.1 with jQuery form submit handler. On submit the textarea is empty, which to me is not correct. However there is an easy workaround which you can use, presuming all your CKEditor textareas have the css class ckeditor.

    $('textarea.ckeditor').each(function () {
       var $textarea = $(this);
       $textarea.val(CKEDITOR.instances[$textarea.attr('name')].getData());
    });
    

    Execute the above before you do your submit handling ie. form validation.

    0 讨论(0)
提交回复
热议问题