EasyUI Forum
May 21, 2024, 12:31:39 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: [SOLVED]Form check if anything is changed or not  (Read 1576 times)
jega
Full Member
***
Posts: 191


View Profile
« 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
« Last Edit: May 30, 2022, 07:09:08 AM by jega » Logged
jega
Full Member
***
Posts: 191


View Profile
« Reply #1 on: May 30, 2022, 01:47:51 AM »

Is there anyone that have an solution.



Jesper
Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #2 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
}
}
})
Logged
jega
Full Member
***
Posts: 191


View Profile
« Reply #3 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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!