使用dojo验证/清除所有输入框 [英] Validating / clearing all inputboxes using dojo

查看:127
本文介绍了使用dojo验证/清除所有输入框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)我有一个dojo小部件,其中加载了2个widgets.Now在某些时候我想要清除widget中的所有文本框。一种方法是:

1)I have a dojo widget inside which i loads 2 more widgets.Now at some point i want to clear all text boxes within the widget.One method is :

this.myAttachPoint.value="".

但这样做会增加代码行。我如何使用一些替代代码来清除所有字段?

But doing this will increase lines of code.How can i use some alternative code that clears all fields ?

2)另外对于验证我正在检查每个字段。 EG

2)Also for validations i was checking each field. EG

if(this.myAttachpoint.value.trim() == "" ){
 //show soime error message
}

现在我的小部件有50个字段,可以有任何人建议我一些选择吗?

Now i have 50 fields in my widgets and its increasing lines of code.Can any one suggest me some alternative?

推荐答案

将所有文本框放在 dijit.form.Form 元素。
当你想清除所有的文本框时,你可以执行

Put all your textboxes inside a dijit.form.Form element. When you want to clear all of the textboxes then you can do

dojo.forEach(dijit.byId('myForm').getDescendants(), function(formWidget) {
    formWidget.attr('value', null);
    //or you could just clear the displayedValue, or...
});

其中myForm是您的dijit.form.Form小部件的ID。

where myForm is the id of your dijit.form.Form widget.

这只适用于文本框,所以不要在窗体中放置任何其他类型的窗体小部件。

This will only work for textboxes so don't put any other type of form widgets inside the form.

这将清除所有文本框的形式。如果你只想清除一些元素,那么你将不得不在你的forE循环中引入条件逻辑。

This will clear all text boxes in the form. If you only want to clear some of the elements then you will have to introduce conditional logic into your forEach loop.

这篇关于使用dojo验证/清除所有输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆