Threaded View

  1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    2
    Vote Rating
    0
    jmartinez40 is on a distinguished road

      0  

    Default Answered: ComboBox custom template - how do I attach a click handler

    Answered: ComboBox custom template - how do I attach a click handler


    I have constructed a ComboBox with a custom Template. Inside this template I have anchor links for which I need to handle the 'click' event. I don't know if this is the best way to implement such functionality, so if there is a better way I am all ears.
    ComboBox-Tpl.jpg
    Last edited by jmartinez40; 2 Dec 2011 at 9:12 AM. Reason: Code was missing

  2. You should be able to specify listeners in the listConfig of the combobox. They will then apply to the drop-down.

    I think you've misunderstood Mitchell's example. He's using event delegation. That involves attaching a single listener to the whole list. The delegate setting then ensures that your listener only fires when a suitable element is clicked. Using this technique there's no need to bind to each row in the list, in fact it will even cope when the contents of the list changes.

    I haven't tried it but you could probably do something like this...

    Code:
    Ext.create('Ext.form.field.ComboBox', {
        ...
        listConfig: {
            listeners: {
                el: {
                    click: {
                        delegate: 'a.iol-combo-list-item-action',
                        fn: function(ev, anchor) {
                            ...
                        }
                    }
                }
            }
        }
    });
    Check out the docs for these settings for more info.