Maciej Kucharz
Maciej Kucharz

Reputation: 1443

Disabling FieldSet items when it is collapsed

I have Ext.form.FieldSet with some fields in it. It looks like:

var register_options = new Ext.form.FieldSet({
    autoHeight: true,
    title: 'My Title',
    checkboxToggle: true,
    checkboxName: 'register_options',
    items: [item1, item2, item3]
});

When my fieldset checkbox is unchecked (fieldset is collapsed) i don't want submit any of its fields (item1, item2...).

I can do this by adding some listeners and disabling fields:

listeners: {
    collapse: function(p) {
        p.items.each(function(i) {
            i.disable();
        },
        this);
    },
    expand: function(p) {
        p.items.each(function(i) {
            i.enable();
        },
        this);
    }
}

Is it proper way, how can i do this better?

Upvotes: 0

Views: 5174

Answers (2)

Mike Perz
Mike Perz

Reputation: 31

Yeah, the cascade function (as suggested by IT Grunt above) worked for me:

listeners: {
    collapse: function(p) {
        p.cascade(function () {
            this.disable();
        });
    },
    expand: function(p) {
        p.cascade(function () {
            this.enable();
        });
    }
}

Upvotes: 1

It Grunt
It Grunt

Reputation: 3378

I don't see anything wrong with your code as long as it works. An alternate that is not as elegant would involve using the cascade function to drill down into the containers.

Upvotes: 1

Related Questions