ExtJs4如何递归禁用面板上的所有字段和所有按钮

发布于 2025-01-07 15:07:36 字数 155 浏览 3 评论 0原文

我试图禁用面板上所有可点击、可编辑的组件。

调用 panel.disable() 会将其变灰,但按钮仍然可单击。 同样的结果为 panel.cascade 提供了一个禁用每个组件的函数。

这样做的正确方法是什么?

I'm trying to disable all clickable, editable components on my panel.

Calling panel.disable() grays it out, but buttons are still clickable.
The same result gives panel.cascade with a function that disables each component.

What is the right way to do this?

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

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

发布评论

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

评论(4

听闻余生 2025-01-14 15:07:36

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

myFormPanel.query('.field, .button').forEach(function(c){c.setDisabled(false);});

(根据表单的复杂性修改您的选择器。您可以只使用 .component ,它将禁用您中的所有组件表单)

另请参阅 - Ext.ComponentQuery

如果您使用 < strong>3.x,可以达到同样的效果像这样分两步 -

myFormPanel.buttons.forEach(function(btn){btn.setDisabled(true);}); //disable all buttons
myFormPanel.getForm().items.each(function(itm){itm.setDisabled(true)}); //disable all fields

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

myFormPanel.query('.field, .button').forEach(function(c){c.setDisabled(false);});

(Modify your selector based on the complexity of your form. You can just use .component and it will disable all component in your form)

See also - Ext.ComponentQuery

If you are using 3.x, you can achieve the same effect in two steps like this -

myFormPanel.buttons.forEach(function(btn){btn.setDisabled(true);}); //disable all buttons
myFormPanel.getForm().items.each(function(itm){itm.setDisabled(true)}); //disable all fields
风尘浪孓 2025-01-14 15:07:36

假设您使用了 FormPanel,您可以使用此方法来获取表单:

getForm() // see http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Panel-method-getForm

这将返回 Ext.form.Basic 对象。从这里,您可以使用方法访问此表单上的所有字段:

getFields() // see http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic-method-getFields

现在您可以迭代该字段并禁用它们。另请注意 applyToFields() 方法,您可以在其中传递对象。请参阅 API 信息:http: //docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic-method-applyToFields

祝你好运!

Assuming that you used a FormPanel you can use this method to get form:

getForm() // see http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Panel-method-getForm

This will return the Ext.form.Basic object. From here you have access to all the fields on this form with method:

getFields() // see http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic-method-getFields

Now cou can iterate through the field and disable them. Notice also the method applyToFields() where you can pass your object. See API information: http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Basic-method-applyToFields

Good luck!

失去的东西太少 2025-01-14 15:07:36

这是禁用表单面板内所有表单字段的更好解决方案。

var formPanelName = Ext.ComponentQuery.query('#formPanelId field');
for(var i= 0; i < formPanelName.length; i++) {
   formPanelName[i].setDisabled(true);
}

只需获取对表单面板字段的引用即可。迭代每个字段并使用 setDisabled 函数将其 readOnly 属性设置为 true。

您还可以更进一步,抓取整个表单面板。上面的解决方案仅通过 ID 获取表单面板的各个部分。外部4

This is a better solution to disabling all form fields inside a form panel.

var formPanelName = Ext.ComponentQuery.query('#formPanelId field');
for(var i= 0; i < formPanelName.length; i++) {
   formPanelName[i].setDisabled(true);
}

Just get a reference to the form panel fields. Iterate over each field and use the setDisabled function to set its readOnly attribute to true.

You can also take it a set further and grab the entire form Panel. This solution above only grabs individual sections of the form panel by its ID. extjs 4

煞人兵器 2025-01-14 15:07:36

对于那些手动将字段集和字段添加到表单面板的人来说,ExtJS 不需要您通过首先执行 getForm() 来直接将组件添加到表单中。它主要是为了方便,并允许标准功能正常工作。因此,无论您从哪个组件进行“添加”,都从该组件进行迭代。

示例 1:

通常您不应该使用“id”来获取组件,因为它是动态设置的。但这显示了如何使用 getCmp 获取表单面板本身。

            var formPanel = Ext.getCmp('id-of-component');
            var fieldSet = Ext.create('Ext.form.FieldSet', {
                title: 'field set'                    
            });
            formPanel.add(fieldSet);

迭代时,您将执行以下操作:

formPanel.each(function(item) {
  alert(item.title);
});

示例 2:

在本示例中,我们添加到实际表单本身,因此迭代看起来略有不同。

            var formPanel = Ext.getCmp('id-of-component');
            var fieldSet = Ext.create('Ext.form.FieldSet', {
                title: 'field set'                    
            });
            formPanel.getForm().add(fieldSet);

迭代时,您可以这样做:

formPanel.getForm().each(function(item) {
  alert(item.title);
});

For those manually adding fieldsets and fields to a form panel, ExtJS doesn't require you to add components directly to the form, by doing a getForm() first. It's mainly for convenience, and allows standard functionality to work properly. So whatever component you did the 'add' from, iterate from that component.

Example 1:

Normally you should not use the 'id' to get a component since it's set dynamically. But this shows how you could get the form panel itself using the getCmp.

            var formPanel = Ext.getCmp('id-of-component');
            var fieldSet = Ext.create('Ext.form.FieldSet', {
                title: 'field set'                    
            });
            formPanel.add(fieldSet);

When iterating, you would do this:

formPanel.each(function(item) {
  alert(item.title);
});

Example 2:

In this example, we add to the actual form itself, so the iteration looks slightly different.

            var formPanel = Ext.getCmp('id-of-component');
            var fieldSet = Ext.create('Ext.form.FieldSet', {
                title: 'field set'                    
            });
            formPanel.getForm().add(fieldSet);

When iterating, you would do this:

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