Creating Validation TextArea in DOJO:
Sometimes we may need to do the validation of the data entered in TextArea but unfortunately the default TextArea provided by DOJO will not support the validation .We can create a custom component extending both dijit.form.ValidationTextBox and dijit.form.SimpleTextarea, this will provide the functionality of both the ValidationTextBox and
SimpleTextarea.
dojo.declare(
"ValidationTextarea",
[dijit.form.ValidationTextBox,dijit.form.SimpleTextarea],
{
postCreate: function() {
this.inherited(arguments);
},
validate: function() {
if (arguments.length==0) {
return this.validate(false);
}
return this.inherited(arguments);
},
onFocus: function() {
if (!this.isValid()) {
this.displayMessage(this.getErrorMessage());
}
},
onBlur: function() {
this.validate(false);
}
}
);
We have to add the dojo require for ValidationTextarea - dojo.provide("ValidationTextarea");
Using the ValidationTextarea in jsp page:
<textarea id="clntlocn" name="clntlocn" data-dojo-type="ValidationTextarea" required="true" missingMessage="Enter the Client Location Name" rows="2" cols="20"" maxLength="50" style="resize:none"></textarea>Now we can include all the validations applicable for dijit.form.ValidationTextBox to
ValidationTextarea.
No comments:
Post a Comment