I'm using summernote wysiwyg in a form for writing product descriptions.
Now I'm trying to make it work with jQuery dirtyforms.
It works only in code-view.
After changing the content should appear as dirty.
If the form is dirty the save button has to be unabled (pic1).
How can i check if the summernote textfield has changed? (the content has been changed).
This is the code for dirty check.
var formUpdateChecker = function() {
$s.DirtyForms.ignoreClass = 'ignore-dirty';
$s('form#product-update, form#form-discount, form#draftComanda, form#product-add, #form--addNewAddress, #form--editAddress').dirtyForms({
message: 'Ai facut modificari care ar putea sa nu fie salvate.'
});
$s('form#product-update, form#form-discount, form#draftComanda, form#product-add, #descriere').on('dirty.dirtyforms clean.dirtyforms summernote.change', function(ev) {
var $form = $s(ev.target);
var $submitResetButtons = $s('.btn-save');
if (ev.type === 'dirty') {
$submitResetButtons.removeAttr('disabled').addClass('btn-primary').removeClass('btn-default');
} else {
$submitResetButtons.attr('disabled', 'disabled').removeClass('btn-primary').addClass('btn-default');
}
});
};
Solved.
var summernoteDirty = function(){
var text_content = $s('#descriere').html();
var new_text_content;
var $submitResetButtons = $s('.btn-save');
$s('#descriere, .note-codable, .note-editable').on('summernote.change dirty.dirtyforms clean.dirtyforms', function(){
new_text_content = $s('.note-editable').html();
if(text_content !== new_text_content){
$submitResetButtons.removeAttr('disabled').addClass('btn-primary').removeClass('btn-default');
}else{
$submitResetButtons.attr('disabled', 'disabled').removeClass('btn-primary').addClass('btn-default');
}
});
};