Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

summernote onKeyup event doesn't work as expected

I have summernote editor applied to a textarea and I would like that when I type some text in the editor, that text should be reflected in a div, so I have a textarea and a div#result where the changes should be written on every keyup event :

<textarea class="description"></textarea>

<br>

<div id="result">Text should change here</div>

I am using the callback onKeyup :

$('.description').summernote({
  callbacks: {
    onKeyup: function(e) {
      $("#result").html($('.description').val());
    }
  }
});

Here is the jsfiddle for the demo purpose:

https://jsfiddle.net/vLdhpx5t/1/

When I type some continuous text, the content doesn't change in the div or at least it doesn't change exactly to match the content of my summernote editor

like image 387
medBouzid Avatar asked Oct 21 '25 15:10

medBouzid


1 Answers

It seems like Summernote needs time to do its work (updating the editors window)...

A 200ms timeout solved the strange issue.

$('.description').summernote({
  callbacks: {
    onKeyup: function(e) {
      setTimeout(function(){
        $("#result").html($('.description').val());
      },200);
    }
  }
});

Updated Fiddle

like image 64
Louys Patrice Bessette Avatar answered Oct 23 '25 07:10

Louys Patrice Bessette



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!