EasyUI Forum
April 20, 2024, 03:20:17 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: Avoid the "onSelect" event to run during the initial loading of form data  (Read 9659 times)
rezzonico
Full Member
***
Posts: 182


View Profile
« on: December 25, 2016, 03:49:06 PM »

Hi all,

I want to avoid the "onSelect" event to run during the initial loading of form data.

Therefore I have modified my program similary to the following thread:
http://www.jeasyui.com/forum/index.php?topic=6088.0

Here is the link to my program:
http://195.144.40.170/jeasyui/QQQ/index.html

As you can see in the web console, the "onLoadSuccess" event is executed before the "onSelect" event.
Therefore when the "onSelect" event is executed, the value of the variable "flag" is true (and not false as expected).

Any help to solve this problem is appreciated.

Regards.
Miche
« Last Edit: December 25, 2016, 04:04:49 PM by rezzonico » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: December 26, 2016, 02:07:26 AM »

You called:
Code:
$('#fm').form('load',{
PdL_ID: '10'
});
So that the form is loaded immediately without any delays and the 'onLoadSuccess' event fires first.
The 'url' property is set to the combobox to retrieved data from remote server, so the combobox data is loaded later and the 'onSelect' event fires after the 'onLoadSuccess' event.
Logged
rezzonico
Full Member
***
Posts: 182


View Profile
« Reply #2 on: December 26, 2016, 03:15:20 AM »

Hi Stworthy ,

I understand what you mean, but I am not able to find a solution.

I have tryed to create the combobox with javascript after the form load:
http://195.144.40.170/jeasyui/QQQ/index1.html

I also have tryed to create the combobox with javascript after the form onLoadSuccess:
http://195.144.40.170/jeasyui/QQQ/index2.html

None of this solution works.

Can you please help me with a short example ?
Thanks

Strange is that if I replace the onSelect event with the onChange event it works (can this be a correct solution ?):
http://195.144.40.170/jeasyui/QQQ/index3.html


Regards
Miche
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: December 26, 2016, 06:50:40 AM »

The 'onChange' event fires when the value is changed. The 'onChange' event is triggered before the 'onLoadSuccess'. When the combobox loads data successfully, the 'onSelect' event fires but the 'onChange' event does not fire again because the value isn't changed.
Logged
rezzonico
Full Member
***
Posts: 182


View Profile
« Reply #4 on: December 26, 2016, 07:05:41 AM »

Thanks a lot for your help.

This means that I can use the onChange event as in the following example:
http://195.144.40.170/jeasyui/QQQ/index3.html
correct ?

But if I would use onSelect, how can I prevent the onSelect event from firing during the form load ?

Thanks again for your patience.

Regards
Michelangelo
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #5 on: December 26, 2016, 09:35:41 AM »

A possible solution to solve this issue is to define two functions to disable or enable the 'onSelect' event.
Code:
function disableOnSelect(f){
($(f).hasClass('combobox-f')?$(f):$(f).find('.combobox-f')).each(function(){
var opts = $(this).combobox('options');
opts.oldOnSelect = opts.onSelect;
opts.onSelect = function(){};
});
}
function enableOnSelect(f){
($(f).hasClass('combobox-f')?$(f):$(f).find('.combobox-f')).each(function(){
var opts = $(this).combobox('options');
opts.onSelect = opts.oldOnSelect;
});
}

Before calling the 'load' method, disable the 'onSelect' event.
Code:
disableOnSelect('#fm');
$('#fm').form('load',{
PdL_ID: '10'
});
After loading the combobox data successfully, enable the 'onSelect' event again.
Code:
<input class="easyui-combobox" name="PdL_ID" data-options="
valueField: 'PdL_ID',
textField:  'PdL_ID',
url: 'data.json',
onLoadSuccess: function(){
enableOnSelect(this);
},
onChange: function(value) {
console.log('onSelect is executed, flag = ' + flag);
}
">
Logged
rezzonico
Full Member
***
Posts: 182


View Profile
« Reply #6 on: December 26, 2016, 10:37:24 AM »

Thanks a lot.

Since (as you wrote) the 'onChange' event is triggered before the 'onLoadSuccess', I will use the solution with the onChange event as in the following program:
http://195.144.40.170/jeasyui/QQQ/index3.html

Regards
Miche
« Last Edit: December 26, 2016, 11:02:58 AM by rezzonico » 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!