Results 1 to 5 of 5

Thread: Form Panels and recursive getValues()

  1. #1
    Sencha User
    Join Date
    Mar 2013
    Posts
    18
    Vote Rating
    0
      0  

    Default Unanswered: Form Panels and recursive getValues()

    How can I turn off or otherwise alter the behavior of Form Panels in terms of the recursive search for form values?

    I have a form composed of some basic form elements as well as some compound form elements that I have created myself. The compound form elements, in turn, contain a number of other basic form elements or yet more compound form elements.

    I need to specially format the data returned from my compound form elements so I have provided a custom getValue() implementation. The problem is, the Form Panel still digs down into my compound form elements and grabs the data from their inner pieces. For example, I might get form values that look like this:

    Code:
    {
      basicInput1:value,
      basicInput2:value,
      compoundInput:{
        subInput1:value,
        subInput2:value
      },
      subInput1:value,
      subInput2:value
    }

    How can I stop this from happening?

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,326
    Answers
    3884
    Vote Rating
    1297
      0  

    Default

    Try setting isField to false on the subInput1, that should skip the items from getting the value and you can handle it in your compound item.
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Mar 2013
    Posts
    18
    Vote Rating
    0
      0  

    Default

    Quote Originally Posted by mitchellsimoens View Post
    Try setting isField to false on the subInput1, that should skip the items from getting the value and you can handle it in your compound item.
    How should I set that to false? I tried passing
    Code:
    {isField:false}
    in the Ext.create() call, but no change. I also tried doing
    Code:
    subinput.isField = false
    , still no luck.

  4. #4
    Sencha User
    Join Date
    Mar 2013
    Posts
    18
    Vote Rating
    0
      0  

    Default

    I just inspected the subinput and I see that the isField property is sitting down within the __proto__, but whatever I do with isField happens at the object root.

    How can I affect change on the __proto__ definition at Ext.create() time?

  5. #5
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,326
    Answers
    3884
    Vote Rating
    1297
      1  

    Default

    Here is a little example:

    Code:
    Ext.define('MyField', {
        extend : 'Ext.Container',
        xtype  : 'myfield',
    
        isField : true,
    
        config : {
            value : null,
            name  : null,
            items : [
                {
                    xtype       : 'textfield',
                    placeHolder : 'First',
                    name        : 'first',
                    isField     : false
                },
                {
                    xtype       : 'textfield',
                    placeHolder : 'Last',
                    name        : 'last',
                    isField     : false
                }
            ]
        },
    
        updateValue : function(value) {
            var fields = this.query('textfield'),
                field1 = fields[0],
                field2 = fields[1];
    
            field1.setValue(value[field1.getName()]);
            field2.setValue(value[field2.getName()]);
        },
    
        getValue : function() {
            var fields   = this.query('textfield'),
                field1   = fields[0],
                field2   = fields[1],
                value1   = field1.getValue(),
                value2   = field2.getValue(),
                value    = {},
                gotValue = false;
    
            if (value1) {
                gotValue = true;
                value[field1.getName()] = value1;
            }
    
            if (value2) {
                gotValue = true;
                value[field2.getName()] = value2;
            }
    
            return gotValue ? value : gotValue;
        }
    });
    
    Ext.Viewport.add({
        xtype : 'formpanel',
        items : [
            {
                xtype       : 'textfield',
                placeHolder : 'Test',
                name        : 'test'
            },
            {
                xtype : 'myfield',
                name  : 'name'
            },
            {
                xtype   : 'button',
                text    : 'setValues',
                handler : function (button) {
                    var form = button.up('formpanel');
    
                    form.setValues({
                        test : 'foo',
                        name : {
                            first : 'John',
                            last  : 'Doe'
                        }
                    });
                }
            },
            {
                xtype   : 'button',
                text    : 'getValues',
                handler : function (button) {
                    var form   = button.up('formpanel'),
                        values = form.getValues();
    
                    console.log(values);
                }
            }
        ]
    });
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it!

    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

Tags for this Thread

Posting Permissions

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