admin管理员组文章数量:1335386
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="panycity" name="panycity" class="textinput" value="<?php echo set_value('panycity'); ?>" style="<?php if(isset($errorData['panycity'])){echo $errorData['panycity'];} ?>"
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 bees 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('panycode').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.
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="panycity" name="panycity" class="textinput" value="<?php echo set_value('panycity'); ?>" style="<?php if(isset($errorData['panycity'])){echo $errorData['panycity'];} ?>"
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 bees 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('panycode').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.
Share Improve this question edited Jun 5, 2010 at 11:10 Eric LaForce asked Jun 5, 2010 at 0:29 Eric LaForceEric LaForce 2,15115 silver badges24 bronze badges2 Answers
Reset to default 4I determined that I was doing this incorrectly. 'validate' and 'validator' are not appropriate attributes for the dojo ValidationTextBox. They both throw errors in Firebug of the form "this.validate is not a function". So at first it looked like this was working for me in the sense it was no longer trying to validate fields, but this is only because errors were being throw.
A better solution was to set the "required" attribute to false upon load.
<input type="text" id="panycode" name="panycode" class="textinput" value="<?php echo set_value('panycode'); ?>" style="<?php if(isset($errorData['panycode'])){echo $errorData['panycode'];} ?>"
dojotype="dijit.form.ValidationTextBox"
required="false" trim="true"
regexp="(^[A-Za-z]{2}-[0-9]{5}$)"
invalidMessage="Invalid value. Must be a valid pany code of the form EX-00000">
Then when a field became visible, set the required attribute back to true.
dijit.byId('panycode').required = true
ValidationTextBox expects validator to be a function, so while you can give it a string value in your markup, what's actually happening is that string is being converted to a function when the instance is created. Setting required is the right way to go, but to be safe I'd suggest using
dijit.byId("panycode").attr("required", true/false)
..to make sure state is correctly updated in the widget.
本文标签: javascriptDisable Dojo validation on certain fieldsStack Overflow
版权声明:本文标题:javascript - Disable Dojo validation on certain fields - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742389634a2465730.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论