einarmagnus
einarmagnus

Reputation: 3592

Is there really no way to hook into the reset event of an Ext.js component?

When I reset a form in Ext.js it resets every child component, but the only events fired are invalid and valid. It seems a bit "hacky" to hook them to handle the clearing of a value, is there no other way? The "problem domain" is that I am writing a plugin to create dependent comboboxes:

Ext.plugins.combobox.DependsOn = function(dependsOn) {
    function init() {
        var cb = this,
            parent = Ext.getCmp(dependsOn);

        parent.on("disable", function() {
            cb.clearValue();
            cb.disable();
        });

        parent.on("select", function() {
            cb.disable(); // dependents will be disabled
            cb.clearValue();

            cb.getStore().load();
            cb.enable();
        });

    }
    return {
        init: function(cb) {
            cb.afterRender = cb.afterRender.createSequence(init);
        }
    }
};

This works well until I call form.reset() at which point the comboboxes remain enabled but empty. I'd like to be able to hook some reset event and there disable and enable my top component to cascade a disabled state downwards. Alas, it seems impossible but I hope someone has a smart answer.

Thank you.

Upvotes: 1

Views: 489

Answers (1)

Florian
Florian

Reputation: 69

Assuming "parent" is an Ext.form.Field, you could use createSequence on parent.reset.

parent.reset = parent.reset.createSequence(function(){
    //here, do what you would have done with parent.on('reset', ...)
});

Upvotes: 1

Related Questions