Victor
Victor

Reputation: 17097

extjs combo override : why define this.addevents()?

In the existing ext js code in the application, a combo box is overriden like this:

Ext.override(Ext.form.ComboBox, {
    nullable:true
    ,initComponent: Ext.form.ComboBox.prototype.initComponent.createSequence(function(){
        this.triggerConfig = {
            tag:'span', cls:'x-form-twin-triggers', cn:[
                {tag: "img", src: Ext.BLANK_IMAGE_URL, cls:'x-form-trigger '},
                {tag: "img", src: Ext.BLANK_IMAGE_URL, cls:'x-form-trigger x-form-clear-trigger'}
        ]};
        this.addEvents(
            'clear',
            'change'
        );

}})

Why do we need to define:

this.addEvents(
                'clear',
                'change'
            );

'change' is already defined as an event for combobox in extjs. 'clear' is not defined in extjs.

EDIT: Maybe a reference to the actual example will help: Here it is. http://www.sencha.com/forum/showthread.php?84300-Nullable-ComboBox&p=404222&langid=14

Upvotes: 1

Views: 1946

Answers (1)

Mchl
Mchl

Reputation: 62395

You'll see that there's this method defined there:

clearValue:Ext.form.ComboBox.prototype.clearValue.createSequence(function(){
        if(this.trigger_clear){
            this.trigger_clear.hide();
        }
        this.fireEvent('clear',  this);
        this.fireEvent('change', this);
    })

So both events are called with only one argument passed (being the combobox itself). I don't think it was necessary to define change event here, since it is inherited from Ext.form.Field. Also the signature of inherited change event is (field, newValue, oldValue) while here, only one argument is passed. Because of that, I think another name should be used for this event.

Upvotes: 1

Related Questions