Search code examples
jquerylaravelsummernote

How to enable or disable button according to what summernote have as text inside?


I have a form wizard in the first step there is summernote and a next button by the id "change_summernote" if the summernote contains text enable else disable (even after user enters text and then delete it ) this is my code:

$(".summernote").on("summernote.keyup", function (we,e) { 
                if(e.keyCode == 46 || e.keyCode == 8)
                {
                    if ( jQuery(".summernote").summernote("code") == '') 
                    {
                        //this line is not working
                        jQuery('#change_summernote').attr("disabled");

                    } else {

                        jQuery('#change_summernote').removeAttr("disabled");
                        //No guarantee it isn't mindless gibberish, sorry.

                    }   
                }
                else
                {
                    jQuery('#change_summernote').removeAttr("disabled");
                }
            });

the part when the next button is diabled if the all text inside summernote is deleted is not working


Solution

  • Correct way of setting attribute using JQuery.

    jQuery('#change_summernote').attr('disabled', 'disabled');