EasyUI Forum
November 04, 2025, 04:56:00 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: form onChange [Solved]  (Read 25051 times)
devnull
Sr. Member
****
Posts: 431


View Profile
« on: December 16, 2014, 03:47:49 AM »

Is it possible to have an event trigger when any element in a form is changed whilst still maintaining the existing onChange() events which have already been binded to any input in the form ?

Thanks
« Last Edit: January 03, 2015, 05:18:23 PM by devnull » Logged

-- Licensed User --
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #1 on: December 16, 2014, 06:59:40 PM »

Please download the patch from http://www.jeasyui.com/download/downloads/jquery-easyui-1.4.1-patch.zip. This patch adds 'onChange' event to the form plugin.
Code:
$('#ff').form({
  onChange: function(target){
    console.log(target);
  }
});
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #2 on: December 16, 2014, 07:42:13 PM »

Wow ! thanks so much.

I just included the js patch into the page (renamed to eui.form.onchange.js), but it does not appear to fire, is there anything else I need to do ??

Code:

<script src="js/jquery-easyui-1.4.1/jquery.easyui.min.js" type="text/javascript">
<script src="js/jquery-easyui-1.4.1/eui.form.onchange.js" type="text/javascript">

$.extend($.fn.form.defaults, {

  onChange: function(target){
    console.log(target);
  }

})

Logged

-- Licensed User --
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #3 on: December 16, 2014, 08:02:53 PM »

Before using the 'onChange' event, you have to create the form component programmatically or add 'easyui-form' class to the <form> element.
Code:
$('#ff').form({
  //...
});
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #4 on: December 16, 2014, 08:08:38 PM »

Hi;

Thanks, yes I know that, I have several dozen pages all with forms that are working perfectly.

But what I am trying to achieve is to have some default action that will be taken unless a form has an override of the default setup.

Can this be done ?

« Last Edit: December 16, 2014, 08:11:37 PM by devnull » Logged

-- Licensed User --
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #5 on: December 16, 2014, 08:23:30 PM »

Override the $.fn.form.defaults.onChange to define the default behavior.
Code:
$.extend($.fn.form.defaults, {
onChange:function(t){
console.log('form onChange')
}
})

You can also override the 'onChange' on the specified form.
Code:
<form class="easyui-form" data-options="
onChange: function(t){
console.log('overriden onChange')
}
">
<input class="easyui-textbox">
</form>
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #6 on: December 16, 2014, 08:33:39 PM »

Thanks, yes that's what I have already.

I can get it to fire when I attach to a specific form, but it does not appear to fire when using the eui extend defaults.



Logged

-- Licensed User --
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #7 on: December 16, 2014, 08:43:16 PM »

If you want to let the both 'onChange' events to be triggered, please try to override the form plugin.
Code:
(function($){
var plugin = $.fn.form;
$.fn.form = function(options, param){
if (typeof options == 'string'){
return plugin.call(this, options, param);
} else {
return this.each(function(){
plugin.call($(this), options, param);
var opts = $(this).form('options');
var onChange = opts.onChange;
if (onChange && onChange != $.fn.form.defaults.onChange){
opts.onChange = function(t){
$.fn.form.defaults.onChange.call(this, t);
onChange.call(this, t);
}
}
});
}
};
$.fn.form.methods = plugin.methods;
$.fn.form.defaults = plugin.defaults;
$.fn.form.parseOptions = plugin.parseOptions;
})(jQuery);
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #8 on: December 18, 2014, 02:09:58 AM »

Sorry, I got distracted and have been working on other issues.

Code:
$.extend($.fn.form.defaults, {
onChange:function(t){
console.log('form onChange')
}
})

This does not fire at all in my system, does it fire in yours ??


Logged

-- Licensed User --
jarry
Administrator
Hero Member
*****
Posts: 2300


View Profile Email
« Reply #9 on: December 18, 2014, 04:06:12 AM »

Please try the attached example 'test.html'.
Logged
devnull
Sr. Member
****
Posts: 431


View Profile
« Reply #10 on: January 03, 2015, 05:18:09 PM »

Hi Jarry;

This is a REALLY useful feature thanks so much for adding it, will it be part of the standard code ??

Logged

-- Licensed User --
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!