Extjs 4:立即禁用 Extjs 表单中的所有输入元素

发布于 2025-01-05 21:40:05 字数 644 浏览 4 评论 0原文

我创建了一个 extjs 表单,它使用列布局分为 2 部分,其中有近 10-15 个输入元素。我如何根据条件一次禁用所有这些输入元素。目前我已经创建了一个函数,它获取表单中的所有组件,并使用 ext.each 循环遍历每个元素来禁用它们

这是我使用的函数

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();
        }
    });
}

是否有任何替代方法,以便我可以禁用所有元素而不循环遍历每个元素每个元素。 我也想在其他表单中使用此功能。我正在寻找类似“setFieldDefult”功能的东西。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

后知后觉 2025-01-12 21:40:05

如果您在 ExtJs 4.x 中使用 FormPanel,这就是您正在寻找的 -

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

getForm() 方法返回 Ext.form.Basic 对象,通过此类,您还可以访问所有使用 getFields() 在此表单上的字段,然后您可以迭代所有字段来执行任何操作。

希望这有帮助,祝你好运:-)

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:-)

十雾 2025-01-12 21:40:05

面板的禁用/启用方法怎么样?这看起来容易多了。

panel.disable();

panel.enable();

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

panel.disable();

panel.enable();
花落人断肠 2025-01-12 21:40:05

这是一个建议.. 既然您说您的表单分为两部分,为什么不将它们放在 FieldSet ?您可以使用一种方法禁用整个字段集,即

这将避免组件循环以及逐个禁用/启用它们。

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.

寂寞笑我太脆弱 2025-01-12 21:40:05

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文