1. #1
    Sencha User
    Join Date
    Aug 2011
    Location
    Mumbai, India
    Posts
    115
    Vote Rating
    3
    Answers
    11
    Sasha172 is on a distinguished road

      0  

    Default Answered: Select/Date/Radio Field data not stored using getValues()

    Answered: Select/Date/Radio Field data not stored using getValues()


    Hi,

    I have a form panel containing various text fields, one selectfield, one datepickerfield, and one radiofield. I have a save button that when pressed dispatches to a controller which saves the data to the store and then populates a list that uses that store. The textfield data saves to the store wid no problems. But the select, datepicker and radio fields do not. Please help.

    Heres the code for the form :

    Code:
    var formPane = new Ext.form.FormPanel ({
        id : 'formPane',
        items: [
            {
                xtype : 'fieldset',
                title : 'Form Details',
                defaults : {
                      labelAlign : 'left',
                      labelWidth : '40%',
                      required : false,
                      useClearIcon : true,
                      autoCapitalize: false
                },
                items : [
                    {
                        xtype: 'textfield',
                        id : 'name',
                        name : 'name',
                        label: 'Name'
                    },
                    {
                        xtype: 'selectfield',
                        name : 'categ',
                        id : 'categ',
                        label: 'Category',
                        valueField : 'categv',
                        displayField : 'title',
                        store : BReimb.stores.categsStore
                    },
                    {
                        xtype: "datepickerfield",
                        name: "date",
                        id : 'date',
                        label: "Date",
                        picker: {yearFrom: 2010}  
                    },
                ]
            },
            {
                xtype : 'fieldset',
                title : 'Radio Details',
                layout : 'hbox',
                defaults : {xtype : 'radiofield'},
                items : [
                    {name : 'paymeth', label: 'Cash', value : 'red', width: '50%'},
                    {name : 'paymeth', width: '50%', label: 'Card' , checked : true, value : 'green'}
                ]
            }
       ]
    });
    Here's the save button in the toolbar :
    Code:
    {
                xtype : 'button',
                text : 'save',
                ui : 'confirm',
                width : '25%',
                handler : function() {
                    Ext.dispatch({
                        controller : 'Users',
                        action : 'save',
                        data : Ext.getCmp('formPane').getValues()
                    });
                 }
    }
    My Controller :
    Code:
    save : function(params){
            App.stores.ListStore.create(params.data);
    }
    The store is set to autoLoad
    The model has a "localstorage" proxy & has string fields with matching ids to the form.

    What am I doing wrong ???

  2. Code:
    new Ext.form.FormPanel({
        fullscreen : true,
        items      : [
            {
                xtype : 'fieldset',
                title : 'Form Details',
                defaults : {
                      labelAlign : 'left',
                      labelWidth : '40%',
                      required : false,
                      useClearIcon : true,
                      autoCapitalize: false
                },
                items : [
                    {
                        xtype: 'textfield',
                        id : 'name',
                        name : 'name',
                        label: 'Name'
                    },
                    {
                        xtype: "datepickerfield",
                        name: "date",
                        id : 'date',
                        label: "Date",
                        picker: {yearFrom: 2010}
                    }
                ]
            },
            {
                xtype : 'fieldset',
                title : 'Radio Details',
                layout : 'hbox',
                defaults : {xtype : 'radiofield'},
                items : [
                    {name : 'paymeth', label: 'Cash', value : 'red', width: '50%'},
                    {name : 'paymeth', width: '50%', label: 'Card' , checked : true, value : 'green'}
                ]
            }
        ],
        dockedItems : [
            {
                xtype : 'toolbar',
                dock  : 'bottom',
                items : [
                    {
                        text    : 'Save',
                        ui      : 'confirm',
                        handler : function(btn) {
                            var form = btn.up('form');
    
                            console.log(form.getValues());
                        }
                    }
                ]
            }
        ]
    });
    The log prints out:

    Code:
    {
        date    : null,
        name    : "",
        paymeth : "green"
    }
    Radios and checkboxes don't have a value if they are not checked.

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    St. Louis, MO
    Posts
    33,599
    Vote Rating
    435
    Answers
    3102
    mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of mitchellsimoens has much to be proud of

      0  

    Default


    Code:
    new Ext.form.FormPanel({
        fullscreen : true,
        items      : [
            {
                xtype : 'fieldset',
                title : 'Form Details',
                defaults : {
                      labelAlign : 'left',
                      labelWidth : '40%',
                      required : false,
                      useClearIcon : true,
                      autoCapitalize: false
                },
                items : [
                    {
                        xtype: 'textfield',
                        id : 'name',
                        name : 'name',
                        label: 'Name'
                    },
                    {
                        xtype: "datepickerfield",
                        name: "date",
                        id : 'date',
                        label: "Date",
                        picker: {yearFrom: 2010}
                    }
                ]
            },
            {
                xtype : 'fieldset',
                title : 'Radio Details',
                layout : 'hbox',
                defaults : {xtype : 'radiofield'},
                items : [
                    {name : 'paymeth', label: 'Cash', value : 'red', width: '50%'},
                    {name : 'paymeth', width: '50%', label: 'Card' , checked : true, value : 'green'}
                ]
            }
        ],
        dockedItems : [
            {
                xtype : 'toolbar',
                dock  : 'bottom',
                items : [
                    {
                        text    : 'Save',
                        ui      : 'confirm',
                        handler : function(btn) {
                            var form = btn.up('form');
    
                            console.log(form.getValues());
                        }
                    }
                ]
            }
        ]
    });
    The log prints out:

    Code:
    {
        date    : null,
        name    : "",
        paymeth : "green"
    }
    Radios and checkboxes don't have a value if they are not checked.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    http://www.JSONPLint.com - Source to lint your JSONP!

    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 almost in print!

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