1. #1
    Sencha User
    Join Date
    Mar 2013
    Posts
    18
    Vote Rating
    0
    studio4development is on a distinguished road

      0  

    Default Unanswered: Form Panels and recursive getValues()

    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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Answers
    3541
    Vote Rating
    847
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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
    studio4development is on a distinguished road

      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
    studio4development is on a distinguished road

      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 - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,330
    Answers
    3541
    Vote Rating
    847
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      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 @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    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.

Thread Participants: 1

Tags for this Thread