EasyUI Forum
May 05, 2024, 07:05:34 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 load with switchbutton don't work  (Read 6959 times)
James
Jr. Member
**
Posts: 52


View Profile Email
« on: August 14, 2018, 01:45:27 AM »

http://jsfiddle.net/j0qruz98/17
« Last Edit: August 14, 2018, 01:48:36 AM by James » Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: August 14, 2018, 02:56:06 AM »

Please parse the components before loading the form. Or wait a little while to load the form data.
Code:
setTimeout(function(){
        var data = {"ismain": "1"};
        $("#test2").form('load', data);
},0);

This example works fine.
http://jsfiddle.net/j0qruz98/20/
Logged
James
Jr. Member
**
Posts: 52


View Profile Email
« Reply #2 on: August 14, 2018, 07:05:46 AM »

Please parse the components before loading the form. Or wait a little while to load the form data.
Code:
setTimeout(function(){
        var data = {"ismain": "1"};
        $("#test2").form('load', data);
},0);

This example works fine.
http://jsfiddle.net/j0qruz98/20/

I see, but this is confuse, why "test2" need it but "test1" don't?
« Last Edit: August 14, 2018, 07:15:43 AM by James » Logged
James
Jr. Member
**
Posts: 52


View Profile Email
« Reply #3 on: August 14, 2018, 07:30:16 AM »

correct me if i'm wrong, is $.parse.auto works like this:
in normal loaded pages , it triggered before other functions , as the script is loaded earlier in "header",
but in ajax loaded pages , it triggered after the the scripts in the loaded page.
if this is what it is, is there any way to make it trigger before those scripts automatically ?
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: August 15, 2018, 01:10:19 AM »

When load a page with script, the script runs immediately. You have to wait for the components to be parsed before loading data on them. The alternative way to solve this issue is to put your code in the 'onLoad' event hander.
Code:
$('#dialog').dialog({
  href: ...,
  onLoad: function(){
    var data = {"ismain": "1"};
    $("#test2").form('load', data);
  }
});
Logged
James
Jr. Member
**
Posts: 52


View Profile Email
« Reply #5 on: August 21, 2018, 08:22:32 PM »

When load a page with script, the script runs immediately. You have to wait for the components to be parsed before loading data on them. The alternative way to solve this issue is to put your code in the 'onLoad' event hander.
Code:
$('#dialog').dialog({
  href: ...,
  onLoad: function(){
    var data = {"ismain": "1"};
    $("#test2").form('load', data);
  }
});

about that , please take a look at http://jsfiddle.net/j0qruz98/30/, if I add $.parser.parse("#test2") to parse components it makes combobox not working,
 if I remove  $.parser.parse("#test2") combobox is ok but switchbutton is not http://jsfiddle.net/j0qruz98/31/ ,
I am so confused , force components to parser, but why combobox can not load the data?
« Last Edit: August 21, 2018, 08:52:10 PM by James » Logged
James
Jr. Member
**
Posts: 52


View Profile Email
« Reply #6 on: August 21, 2018, 08:45:51 PM »

http://jsfiddle.net/j0qruz98/35/

I remove class name from switchbutton and give the element an id , use js with it's id to parse switchbutton, and then all the form components works fine, but this is so confusing and is not easy to use.
Logged
James
Jr. Member
**
Posts: 52


View Profile Email
« Reply #7 on: August 21, 2018, 09:12:02 PM »

by the way, in my opinion, switchbutton is not a perfect form component, it should have an offvalue, when use switchbutton in update form, with form submited, if it is on, I can get the value, but when it is off, you just simply not submit this component as it is not exist in the form, as switchbutton shows, it is most likely use as boolean type, when it is off, at the server side , I have to check if it is exist, then manually set its value.
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!