Validating / clearing all inputboxes using dojo

不问归期 提交于 2019-12-14 03:58:34

问题


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)Also for validations i was checking each field. EG

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

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


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/5401082/validating-clearing-all-inputboxes-using-dojo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!