Disable Dojo validation on certain fields
- by Eric LaForce
I would like to disable client side validation on certain fields in my user form. Currently I have two sets of fields that are displayed depending on the value of a previous drop down list. i.e. if the drop down list is set to value "A" 1 new field appears in the form. If the drop down list is set to value "B" 3 new fields appear in the form (mutually exclusive from the new form field when "A" is selected). Currently my Dojo client side validation fails because the fields that are not shown to the user (and thus no data can be inserted into those fields) fails to validate.
Currently I determined that I can set the "validate" attribute to return true like so:
<input type="text" id="companycity" name="companycity" class="textinput" value="<?php echo set_value('companycity'); ?>" style="<?php if(isset($errorData['companycity'])){echo $errorData['companycity'];} ?>"
dojotype="dijit.form.ValidationTextBox"
required="true" trim="true" validate='return true'"
regexp="([a-zA-Z]{1,25})"
invalidMessage="Invalid value. Must be between 1 and 25 alphabetic characters long.">
This fixes my issue for hidden fields. However this now means that no validation is performed when this field becomes visible to the user (i.e. the validate attribute is still set to return true).
I have tried removing the validate property when a field is displayed to the user like so:
dijit.byId('companycode').attr('validate','');
This just set the attribute to nothing. This however gives errors in firebug saying validate method not found, so I take that to mean I did not remove this attribute correctly or removing this attribute is not the appropriate way to do this.
I have also looked at overriding the validator method here but this doesnt seem like what I want either. I do not want to have to rewrite all the validation methods in place of dojo's.
I just want dojo not to validate if the field is not visible to the user. Thanks for any advice or help.