EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: ClSoft on March 11, 2013, 03:18:08 PM



Title: Read value
Post by: ClSoft on March 11, 2013, 03:18:08 PM
Hi all
I have datagrid and button (Change member)
Under button, I call (onClick) ChangeMember() function, and here is it:

 function changeMember()
  {
    current = $('#members_tree').treegrid('getSelected').id;
    if (current){ 
      // Form
      $('#dlg').dialog('open').dialog('setTitle','Edit Member'); 
      $('#form_member').form('load', 'json/member.json');
      alert($('#zip').val());
    }     
  }

in JSON file, I have "zip" value, but alert is displayed too early, because form is still not filled.
When I click second time on same button, then I see value in alert, but I need it first time.
I try with onLoad event, but it is not fired on that point (onLoad is fired if I call 'load' from opened dialog).

Shortest - how to load JSON file and get some value?
THanks!


Title: Re: Read value
Post by: ClSoft on March 14, 2013, 01:54:11 PM
Here is simple version, maybe someone help me now :)

      // Form
      $('#dlg').dialog('open').dialog('setTitle','Edit Member'); 
      $('#form_member').form('load', '/json/member.json');

      var zip = $('#zip').val();
      alert(zip);     

I have no value in alert first time, and if I call this code for different record, I see (in alert) value from previous record.
How to read value after dialog is opened ?
Thanks!


Title: Re: Read value
Post by: ClSoft on March 18, 2013, 12:40:17 AM
OK maybe I need ask on this way:
how to fill form data (from JSON file) before form is opened?
Basically, I need to disable some fileds based on input value, and I can not do that because for is opened before I read JSON file.
Thanks!


Title: Re: Read value
Post by: stworthy on March 18, 2013, 09:25:10 AM
Try the following code:
Code:
$.get('/json/member.json', function(data){
$('#dlg').dialog('open').dialog('setTitle','Edit Member');
$('#form_member').form('load', data);

var zip = $('#zip').val();
alert(zip);     
});


Title: Re: Read value
Post by: ClSoft on March 18, 2013, 11:40:57 PM
Hello
Thanks stworthy, but...
I can not bring it to work :(

This is what I have:
Under button, I call (onClick) ChangeMember() function, and here is complete function:

function changeMember()
  {
    current = $('#members_tree').treegrid('getSelected').id;
    if (current){ 
      $.get('/json/member.json', function(data){
        $('#dlg').dialog('open').dialog('setTitle','Edit Member');
        $('#form_member').form('load', data);
        var zip = $('#zip').val();
        alert(zip);     
      });
    }     
  }

I'm not sure that above is correct, so please tell me what's wrong?

this is JSON file:

{
    "firstname": "daniela",
    "lastname": "something",
    "zip": 2224
}

Thanks!


Title: Re: Read value
Post by: stworthy on March 19, 2013, 07:32:16 PM
Please refer to the attached example(form_test.zip).


Title: Re: Read value
Post by: ClSoft on March 20, 2013, 12:17:50 AM
Thank you very much, but I can not bring it to work :(
when I run it, I see empty message (see image).
When I click on OK, form is empty.
What I'm doing wrong?


Title: Re: Read value
Post by: stworthy on March 20, 2013, 12:36:25 AM
It works fine in chrome,firebox and ie. Be sure to copy 'form_test.html' and 'member.json' files to your test directory on web server.


Title: Re: Read value
Post by: ClSoft on March 20, 2013, 02:13:07 AM
Hi
yes, I uploaded it to webserver and there it works.
I need to see what's wrong on my local server.
Thanks!


Title: Re: Read value
Post by: ClSoft on March 21, 2013, 07:25:13 AM
Just to inform you stworthy, it work's perferct.
thanks man!