Nick
Nick

Reputation: 1869

Extjs 4 :Disable all the input elemets in an Extjs form at once

I have created a extjs form which is divided into 2 parts using column layout and have almost 10-15 input elements in it. How can i disable all these input elements at a time depending on a condition. Currently i have created a function which fetchs all the components in a form and using ext.each loop through each element to disable them

Here is the function that i use

function prepare_form_view(form){
    var f=Ext.getCmp(form);
    var els=f.query('component');
    Ext.each(els,function(o){
        var xtype=o.getXType();
        if(xtype=='textfield'||xtype=='combobox'||xtype=='datefield'||xtype=='textareafield'||xtype=='button'){
            o.disabledCls='myDisabledClass';
            o.disable();
        }
    });
}

Is there any alternative way so that I can disable all elements without looping through each and every elements. I want to use this function with other forms too. I looking for something like 'setFieldDefult' function.

Upvotes: 3

Views: 12609

Answers (4)

BlueMice
BlueMice

Reputation: 333

If you are using FormPanel in ExtJs 4.x this is what you are looking for -

yourFormPanel.getForm().applyToFields({disabled:true});

The getForm() method returns the Ext.form.Basic object, with this class, you also could access to all the fields on this form with getFields(), then you could iterator all the fields to do anything.

Hope this helps and good luck:-)

Upvotes: 9

Grant Zhu
Grant Zhu

Reputation: 3018

What about panel's disable/enable method? This seems much easier.

panel.disable();

panel.enable();

Upvotes: 4

pater
pater

Reputation: 1251

You could use the cascade function of the form panel which is the ExtJs way to to do it but if you check the source code of the cascade function you will see that it uses a for loop also. The only benifit of using the cascade function is that it will work also for forms with nested panels. I think that your implementation will not work properly a case like that.

Upvotes: 0

Abdel Raoof Olakara
Abdel Raoof Olakara

Reputation: 19353

Here is a suggestion.. Since, you say your form is divided into two parts why don't you put them in a FieldSet ? You can disable the fieldset as a whole with one method ie, setDisabled.

This will avoid the looping of components and disabling / enabling them one after the another.

Upvotes: 1

Related Questions