Results 1 to 2 of 2

Thread: combobox valueField

  1. #1
    Ext User
    Join Date
    Jul 2008
    Location
    Texas
    Posts
    3

    Question combobox valueField

    I have the follwoing combo box in a form panel. It works great except it send the name field instead of the value field to my php script. I have read that you have to use a hidden field to store the value but I keep getting JS errors. Any help would be great. Am I close or way out in left field?
    Code:
     Ext.onReady(function(){
        Ext.QuickTips.init();
     var combo = new Ext.form.ComboBox({
        typeAhead: true,
        triggerAction: 'all',
        lazyRender:true,
        fieldLabel:'Code',
     mode: 'local',
        store: new Ext.data.ArrayStore({
            id: 0,
            fields: [
                'id',
                'code',
                'name'
            ],
            data: [[0, 'VC', 'Vacation'], [1, 'OT', 'Overtime']]
        }),
        valueField: 'code',
        displayField: 'name',
        hiddenName:'hiddenCode',
        name: 'code',
        allowBlank:false
    });
    var hidden = new Ext.form.Hidden({
     name:'loginUsername'
    });
        var login = new Ext.FormPanel({ 
            labelWidth:80,
            url:'login.php', 
            frame:true, 
            title:'Please Login', 
            defaultType:'textfield',
      monitorValid:true,
            items:[{ 
                    fieldLabel:'Username', 
                    name:'loginUsername', 
                    allowBlank:false 
                },{ 
                    fieldLabel:'Password', 
                    name:'loginPassword', 
                    inputType:'password', 
                    allowBlank:false 
                },hidden,combo ],
     
     // All the magic happens after the user clicks the button     
            buttons:[{ 
                    text:'Login',
                    formBind: true,  
                    // Function that fires when user clicks the button 
                    handler:function(){ 
                        login.getForm().submit({ 
                            method:'POST', 
                            waitTitle:'Connecting', 
                            waitMsg:'Sending data...',
     
       // Functions that fire (success or failure) when the server responds. 
     
                            success:function(){ 
                             Ext.Msg.alert('Status', 'Login Successful!', function(btn, text){
           if (btn == 'ok'){
                              var redirect = 'index.html'; 
                              window.location = redirect;
                                       }
               });
                            },
                            failure:function(form, action){ 
                                if(action.failureType == 'server'){ 
                                    obj = Ext.util.JSON.decode(action.response.responseText); 
                                    Ext.Msg.alert('Login Failed!', obj.errors.reason); 
                                }else{ 
                                    Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText); 
                                } 
                                login.getForm().reset(); 
                            } 
                        }); 
                    } 
                }] 
        });
     
     
     // This just creates a window to wrap the login form. 
     // The login object is passed to the items collection.       
        var win = new Ext.Window({
            layout:'fit',
            y:20,
            x: 20,
      width:300,
            height:175,
            closable: false,
            resizable: false,
            plain: true,
            border: false,
            items: [login],
            modal: true
     });
     win.show();
    });

  2. #2
    Ext User
    Join Date
    Jul 2008
    Location
    Texas
    Posts
    3

    Thumbs up Solution

    I was able to fix it by intializing my data store before loading the combobox.

    Code:
     var store = new Ext.data.ArrayStore({
            id: 0,
            fields: [
                'id',
                'code',
                'name'
            ],
            data: [[0, 'VC', 'Vacation'], [1, 'OT', 'Overtime']]
        });
     var combo = new Ext.form.ComboBox({
        typeAhead: true,
        triggerAction: 'all',
        lazyRender:true,
        fieldLabel:'Code',
     mode: 'local',
        store: store,
        valueField: 'code',
        displayField: 'name',
        hiddenName:'hiddenCode',
        name: 'code',
        allowBlank:false
    });

Posting Permissions

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