Tuesday, March 7, 2017

How to validate Summernote using javascript/jquery and reset the value

In this article I am going to show you how to validate and reset Summernote (To know more about summernote click on link). 

So, for this firstly we get the value of editor and store in a variable just like (Editor is id of summernote) :


   1:  var code = $('#Editor').summernote('code');
 
After this we replace symbols like <, >, /  with space ' ', because of the default value of summernote is '<p> <br/> &lt/;p>'
 Final code is :


   1:   var code = $('#Editor').summernote('code');
   2:          var filteredContent = (code).replace(/\s+/g, '');
   3:   
   4:          if (filteredContent.length == 0) {
   5:              $('.note-editable').css({ 'border': 'solid 1px red' }).focus();
   6:              //  if summernote is empty          
   7:              isValid = false;
   8:          }
   9:   

Now, for reset the summernote value :


   1:   $('#Editor').summernote('code', '');
 
I hope ,it will help you.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...