EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: jega on May 23, 2022, 12:53:41 AM



Title: [SOLVED]Form check if anything is changed or not
Post by: jega on May 23, 2022, 12:53:41 AM
Hi.

The onChange event can be fired when an element is changed.

But how to "Unchange" when the user have written something in a textbox, and deleted it again.

What i want is, that when user change something the save button must be enabled, but also when user delete the change, the savebutton must disable again, as no change is done.

Jesper


Title: Re: Form check if anything is changed and reversed
Post by: jega on May 30, 2022, 01:47:51 AM
Is there anyone that have an solution.



Jesper


Title: Re: Form check if anything is changed and reversed
Post by: jarry on May 30, 2022, 02:56:22 AM
Compare the editing data with the original data, if something is changed then enable the saving button.

Code:
$('#ff').form({
originalData: $('#ff').serialize(),
onLoadSuccess: function(data){
var opts = $(this).form('options');
opts.originalData = $(this).serialize();
},
onChange: function () {
var opts = $(this).form('options');
var data = $(this).serialize();
var dirty = data != opts.originalData;
if (dirty){
// enable button
}
}
})


Title: Re: Form check if anything is changed and reversed
Post by: jega on May 30, 2022, 07:08:37 AM
Hi Jarry.

In between i found a solution, and it is similar to yours.

<form id="fmEditProfile" method="post" class="easyui-form" novalidate data-options="
      onLoadSuccess: function() {
         $('#saveButton').linkbutton('disable');
         origForm = $('#fmEditProfile').serialize();
      },
      onChange: function(target){
         if ($(this).serialize() !== origForm) {
            $('#saveButton').linkbutton('enable');
         } else {
            $('#saveButton').linkbutton('disable');
         }
      }">


Thanks anyway