Yes, you're right - you can get all your validation, select and even focus on the first invalid field by simply calling the validate() function in the dijit.form.Form element.
Here is an example in which a validate () call is added to the onSubmit event:
<head> <script type="text/javascript"> dojo.require("dojo.parser"); dojo.require("dojo.form.Form"); dojo.require("dojo.form.ValidationTextBox"); dojo.require("dojo.form.Button"); </script> </head> <body> <form dojoType="dijit.form.Form" action="..." method="..."> <input dojoType="dijit.form.ValidationTextBox" trim="true" regExp="..." invalidMessage="Oops..."> <button type="submit" dojoType="dijit.form.Button" ...> Submit </button> <script type="dojo/method" event="onSubmit"> if (!this.validate()) { alert("Form contains invalid data. Please correct...."); return false; } return true; <script> </form> </body>
I hope you find this helpful.
Greetings.
Follow-up: Here is an example of an input field that can be used to prompt the user about what data is expected, and will warn them that the verification failed:
<input type="text" id="EXT" name="EXT" value="" maxLength="10" dojoType="dijit.form.ValidationTextBox" regExp="\d+?" trim="true" promptMessage="<p class='help'>Please your extension. (ie "1234")</p>" invalidMessage="<p class='help'>The extension field should contain only numbers.</p>">
This is a declarative example. (I made a mistake in this in my original answer below.)
source share