1. #1
    Sencha User
    Join Date
    Oct 2011
    Location
    ukraine
    Posts
    13
    Vote Rating
    0
    vladka is on a distinguished road

      0  

    Default Answered: set current value from combox

    Answered: set current value from combox


    Hello everyone.

    i want to edit object, and set a current value for combox.
    Use this code:
    PHP Code:
                     var metrocombox Ext.create('Ext.form.ComboBox', {           
                          
    fieldLabel'Метро',            
                          
    store:    Ext.create('Ext.data.Store', {                
                                 
    model'EstateMetro',                
                                 
    autoLoadtrue,                
                                 
    minChars1,            
                          }),
                          
    listeners:{
                             
    select:{ 
                                   
    fn:function(combovalue) {
                                            
    Ext.get('mycategory-id').set({valuevalue[0].data.id})                    
                             }                },            },            
                         
    editablefalse,                
                         
    inputId'mycategory-id',            
                         
    displayField'name',            
                         
    valueField'id',            
                         
    name'metro_id',            
                         
    xtype:'combo',            
                        
    allowBlankfalse,            
                        
    width720,            
                        
    triggerAction:'all',            
                        
    mode:'local',        
                   });        

                   
    metrocombox.setValue(1
    panelform.down('form').getForm().setValues(current_data) - did not work (all other values is ok), and
    metrocombox.setValue(1) - not work, why ?

    how to set current value for combox ?

  2. Whoa! Hold your horses. You've gone off in totally the wrong direction.

    I've just taken a look at the code you posted on pastebin. The reason that code doesn't work is because your fields don't match. In your store you've called the field value but in the combobox you've called the field id.

    It's up to you which one you change but the name of the field listed in valueField must also be present in the store's fields. For example, if you change it to:

    Code:
    valueField: 'value'
    then it should work fine.

    You do not need to change your call to setValue(1), that was fine the way it was.

  3. #2
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,490
    Answers
    526
    Vote Rating
    283
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    The value you attempt to set must correspond to a value in the valueField of a record in your store. Do you definitely has a record with the id of 1? Note that the field name is case-sensitive and the value type must match the type in the field (i.e. the record must contain the number 1, not the string '1').

  4. #3
    Sencha User
    Join Date
    Oct 2011
    Location
    ukraine
    Posts
    13
    Vote Rating
    0
    vladka is on a distinguished road

      0  

    Default


    nope

    http://pastebin.com/BTkB7u0B

    just have error message - This fields is requered.

    i think problem somewhere in listeners.

  5. #4
    Sencha User
    Join Date
    Oct 2011
    Location
    ukraine
    Posts
    13
    Vote Rating
    0
    vladka is on a distinguished road

      0  

    Default


    get it.
    i should make:

    directioncombox.setValue({'value': 1, 'name': 'Аренду'})


    thank you, i almost lost belive that setValue works as i need

  6. #5
    Sencha User
    Join Date
    Oct 2011
    Location
    ukraine
    Posts
    13
    Vote Rating
    0
    vladka is on a distinguished road

      0  

    Default


    but i have other question,

    is it possible to override setValue function like this ?

    PHP Code:
    Ext.form.Combox.override({           
                    
    setValue: function(val)  {                
                         
    value this.store.findRecord('value'val);                
                         
    this.calOverridden(value);            
                    }
    }); 
    give me error underfined function override.

    Can some one give me a link to docs where i can find true way to override function in extjs ?
    thank you

  7. #6
    Sencha Premium Member skirtle's Avatar
    Join Date
    Oct 2010
    Location
    UK
    Posts
    3,490
    Answers
    526
    Vote Rating
    283
    skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future skirtle has a brilliant future

      0  

    Default


    Whoa! Hold your horses. You've gone off in totally the wrong direction.

    I've just taken a look at the code you posted on pastebin. The reason that code doesn't work is because your fields don't match. In your store you've called the field value but in the combobox you've called the field id.

    It's up to you which one you change but the name of the field listed in valueField must also be present in the store's fields. For example, if you change it to:

    Code:
    valueField: 'value'
    then it should work fine.

    You do not need to change your call to setValue(1), that was fine the way it was.

  8. #7
    Sencha User
    Join Date
    Oct 2011
    Location
    ukraine
    Posts
    13
    Vote Rating
    0
    vladka is on a distinguished road

      0  

    Default


    Yap!

    and it's work perfectly without listeners!

    thanks !

Thread Participants: 1

Tags for this Thread