Form and JSON reader

  • Hello all,

    I just tried to populate a form with a JSON string generated with PHP.

    Here is my JS code :


    Ext.onReady(function(){

    var myRecord = new Ext.data.Record.create([
    {name:'nomchamp'},
    {name:'typechamp'}
    ]);

    var myReader = new Ext.data.JsonReader({
    successProperty: 'success',
    totalProperty: 'results',
    root: 'champs',
    id: 'nomchamp'
    }, myRecord);


    var fs = new Ext.FormPanel({
    frame: true,
    defaultType: 'textfield',
    reader: myReader,
    items: [{
    fieldLabel: 'Nom',
    name: 'nomchamp',
    }, {
    fieldLabel: 'Type',
    name: 'typechamp',
    }]
    });

    fs.addButton('Load', function(){
    fs.getForm().load({url:'json-form.php', waitMsg:'Loading'});
    });

    fs.render('form-ct');

    });



    and my PHP code

    $StrJSON = '{"success":"true","results":"1","champs":{"nomchamp":"Nom", "typechamp":"Type"}}';
    print $StrJSON;


    but my fields remain blank after a click on the load button.
    Could you help me ???

    Thanks a lot for your help.


  • I just added this to the Form FAQ

    http://extjs.com/learn/Ext_FAQ_Forms


  • The 443th time this has come up...

    Do not use a Reader with a form. Forms understand JSON.

    http://extjs.com/deploy/dev/docs/?class=Ext.form.Action.Load

    http://extjs.com/deploy/dev/docs/?class=Ext.form.Action.Submit







  • #If you have any other info about this subject , Please add it free.#
    Your name:
    E-mail:
    Telphone:

    Your comments:


    If you have any other info about Form and JSON reader , Please add it free.

    15 March 2010 | cameltoepants.com | edit