开发者

Validating / clearing all inputboxes using dojo

开发者 https://www.devze.com 2023-02-18 09:09 出处:网络
1)I have a d开发者_如何转开发ojo widgetinside which i loads 2 more widgets.Now at some point i want to clear all text boxes within the widget.One method is :

1)I have a d开发者_如何转开发ojo 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消