Results 1 to 4 of 4

Thread: SOLVED: FormPanel with JsonReader -- Possible?

  1. #1
    Ext User DynamoEffects's Avatar
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    41

    Default SOLVED: FormPanel with JsonReader -- Possible?

    I'm having the hardest time getting a FormPanel to populate its fields with a remote JSON string and the forums aren't turning up anything. In an effort to make a working example, I've moved over to the xml-form example that comes with Ext but even there it's not working.

    If you'd like to try this, you just need to overwrite your xml-form.js file with the one below and add the new xml-form.php file to the directory.

    xml-form.js
    Code:
    /*
     * Ext JS Library 2.0
     * Copyright(c) 2006-2007, Ext JS, LLC.
     * [email protected]
     * 
     * http://extjs.com/license
     */
    
    Ext.onReady(function(){
    
        Ext.QuickTips.init();
    
        // turn on validation errors beside the field globally
        Ext.form.Field.prototype.msgTarget = 'side';
        
        var recordObj = Ext.data.Record.create([
         'LastName', 'FirstName', 'Email', 'Company'
        ]);
        
        var myReader = new Ext.data.JsonReader({
            root: "data",
            id: "LastName"                                           
        }, recordObj);
    
        var fs = new Ext.FormPanel({
            frame: true,
            title:'XML Form',
            labelAlign: 'right',
            labelWidth: 85,
            width:340,
            waitMsgTarget: true,
            reader: myReader,
            items: [
                new Ext.form.FieldSet({
                    title: 'Contact Information',
                    autoHeight: true,
                    defaultType: 'textfield',
                    
                    items: [{
                            fieldLabel: 'First Name',
                            name: 'FirstName',
                            width:190
                        }, {
                            fieldLabel: 'Last Name',
                            name: 'LastName',
                            width:190
                        }, {
                            fieldLabel: 'Company',
                            name: 'Company',
                            width:190
                        }, {
                            fieldLabel: 'Email',
                            name: 'Email',
                            vtype:'email',
                            width:190
                        }
                    ]
                })
            ]
        });
    
        // simple button add
        fs.addButton('Load', function(){
            fs.getForm().load({url:'xml-form.php', waitMsg:'Loading'});
        });
    
        // explicit add
        var submit = fs.addButton({
            text: 'Submit',
            disabled:true,
        });
    
        fs.render('form-ct');
    
        fs.on({
            actioncomplete: function(form, action){
                if(action.type == 'load'){
                    submit.enable();
                }
            }
        });
    
    });
    xml-form.php -- This is the data sent back
    Code:
    {data:{FirstName:"Bob",LastName:"Barker",Company:"The Price is Right",Email:"[email protected]"}}
    No errors, it simply doesn't update the fields. Anybody see what's not right here?

  2. #2
    Sencha User hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,966

    Default

    Code:
    {success:true, data:{FirstName:"Bob",LastName:"Barker",Company:"The Price is Right",Email:"[email protected]"}}
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  3. #3
    Ext User DynamoEffects's Avatar
    Join Date
    Oct 2007
    Location
    Italy
    Posts
    41

    Default

    That did it! That plus deleting the reader was the secret to getting it work. Thanks for the quick responses today, Doug!

  4. #4
    Sencha User
    Join Date
    Mar 2008
    Posts
    50

    Default

    hello.

    im interested in how to set the value and displayfield for combo in that way?

    thanx in advance

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •