views:

25

answers:

1

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.

A: 

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', ...)
});
Florian
ah, yes. I didn't think of that. It does feel a bit like a hack, but I suppose it is the only way to accomplish what I asked for. Thanks!
ormuriauga