Login Register

Simple, custom form validation - how? docs?

Hello.

Can someone point me at some examples or documentation for adding extra form validation? The ValidationTextBox etc are fine, but often I need to extend the logic for certain forms. This must be a common task.

For example, I have a form with date-of-birth: three FilteringSelect widgets for day, month, year.
Before allowing the form to submit, I need to check that the date is valid - eg 31 Feb is not allowed.

The only example I could find is a comment in the book and it's not working for me.

<form dojoType="dijit.form.Form">

  <script type="dojo/method" event="onSubmit">
    if(this.validate()) {
      return confirm('Form is valid, press OK to submit');
    }
    else {
      alert('Form contains invalid data.  Please correct first');
      return false;
    }
    return true;
  </script>

  <script type="text/javascript">
    // test extra validation:

    dojo.addOnLoad(
      function() {
        dojo.connect(dijit.byId('dob_month'), 'validate', function() { return false; });
      } );
  </script>

  <select name="dob_month" id="dob_month" style="width: 10em;" dojoType="dijit.form.FilteringSelect">
    <!-- options -->
  </select>

  <!-- more widgets -->

</form>

The bound function is called when the form is validated, however the selected month value is considered valid regardless of whether the function returned true or false.

What is the correct way to apply extra validation logic here?

Or checking that a password

Or checking that a password and password-confirmation box match (to avoid user typos).