1. #1
    Sencha User
    Join Date
    Aug 2012
    Posts
    15
    Vote Rating
    0
    messyOne is on a distinguished road

      0  

    Default Unanswered: Add EventListener to a combobox

    Unanswered: Add EventListener to a combobox


    Hi guys,

    I have a PHP code which returns an JSON object. This object consists the data for a combobox. In my ExtJS script the object is embedded. Now I want to add a EventListener to this object, but I get the error "Uncaught TypeError: Object #<Object> has no method 'addListener'" if I try it with the addListerner.

    PHP array for JSON object
    PHP Code:
    $this->metadata['tbar']['combos'][] = array(    
      
    'Test',    
      array(        
        
    'hidden' => false,        
        
    'xtype' => 'combo',        
        
    'width' => 100,        
        
    'store' => $items,        
        
    'value' => $value,    
      )            
    ); 
    ExtJS panel create
    Code:
    Ext.create('widget.panel', {
                width: 1024,
                height: 728,
                renderTo: _this.config.config.dom,
                layout: 'fit',
                items: _this.panelItems,
                tbar : [
                    _this.config.metadata.tbar.combos,
                ]
            }); 
        }    
    }
    _this.config.metadata.tbar.combos is the JSON data for the combobox passed by PHP.

    How can I do it?

  2. #2
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,120
    Vote Rating
    30
    Answers
    85
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    You can add it in the config of the combo. Because only afterrender of the combo you can set the listener.

    Code:
    $this->metadata['tbar']['combos'][] = array(    
      'Test',    
      array(        
        'hidden' => false,        
        'xtype' => 'combo',
        'listeners: '{ render: onComboboxRender }',        
        'width' => 100,        
        'store' => $items,        
        'value' => $value,    
      )            
    );
    and create that render function

    Code:
    onComboboxRender: function(c) {
        c.addListerner(yourlistener);
    }
    Or put all listeners directly in the config of you combo.

  3. #3
    Sencha User
    Join Date
    Aug 2012
    Posts
    15
    Vote Rating
    0
    messyOne is on a distinguished road

      0  

    Default


    Mhh... I have tried it, but no result.

    At first put the listener directly in combo:
    Code:
    $this->metadata['tbar']['combos'][] = array(
        $title,
        array(
            'hidden' => false,
            'xtype' => 'combo',
            'width' => 100,
            'store' => $items,
            'displayField' => 'display',
            'valueField' => 'value',
            'value' => $value,
            'listeners' => '{
                    select: function(combo, records, scope) {
                        console.log("foo");
                    }
                }'   
        )            
    );
    At second: In which position must the onComboboxRender be placed?

  4. #4
    Sencha Premium Member dawesi's Avatar
    Join Date
    Mar 2007
    Location
    Melbourne, Australia (aka GMT+10)
    Posts
    1,083
    Vote Rating
    44
    Answers
    24
    dawesi has a spectacular aura about dawesi has a spectacular aura about

      0  

    Default


    can you add the listener in the config object?

    Code:
    listeners : {
            change : function(myCombo,sel,orig){
                console.log('diff',Ext.Array.remove(myCombo.getValue(),myCombo.originalValue));
                myCombo.setValue(Ext.Array.remove(myCombo.getValue(),myCombo.originalValue));
                }
            }
    Teahouse Training Company
    Official Certified Sencha Trainer

    Australia / New Zealand / Singapore / Hong Kong & APAC



    SenchaWorld.com - Sencha webinars, videos, etc
    SenchaForge.org - (coming soon)
    TeahouseHQ.com - Sencha ecosystem training portal

    Code Validation : JSLint | JSONLint | JSONPLint

  5. #5
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,120
    Vote Rating
    30
    Answers
    85
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    Hmm then this?

    Code:
    $this->metadata['tbar']['combos'][] = array(
        $title,
        array(
            'hidden' => false,
            'xtype' => 'combo',
            'width' => 100,
            'store' => $items,
            'displayField' => 'display',
            'valueField' => 'value',
            'value' => $value,
            'listeners' => '{
                    select: 
                      {
                          fn: function(combo, records, scope) {
                                console.log("foo");
                           }
                      }
                }'   
        )            
    );

  6. #6
    Sencha User
    Join Date
    Aug 2012
    Posts
    15
    Vote Rating
    0
    messyOne is on a distinguished road

      0  

    Default


    @tvanzoelen: Unfortunately it also doesn't work with this.

    @dawesi: The listener "change" also doesn't work.



  7. #7
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,120
    Vote Rating
    30
    Answers
    85
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    And is the store loaded? Else there will be no change or select possible.

  8. #8
    Sencha User
    Join Date
    Aug 2012
    Posts
    15
    Vote Rating
    0
    messyOne is on a distinguished road

      0  

    Default


    Yes! The store is loaded. I have a lot of items in the list.

  9. #9
    Ext JS Premium Member tvanzoelen's Avatar
    Join Date
    Apr 2008
    Location
    Groningen - Netherlands
    Posts
    1,120
    Vote Rating
    30
    Answers
    85
    tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about tvanzoelen has a spectacular aura about

      0  

    Default


    But the error is gone. What happens now? No event, no log?

  10. #10
    Sencha User
    Join Date
    Aug 2012
    Posts
    15
    Vote Rating
    0
    messyOne is on a distinguished road

      0  

    Default


    Oh, yes. The error is gone, but no log.

    Edit: The error came but only if I try to add the listener in the ExtJS script to the object.

Thread Participants: 2