禁用某些字段上的Dojo验证 [英] Disable Dojo validation on certain fields

查看:103
本文介绍了禁用某些字段上的Dojo验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户表单中的某些字段上禁用客户端验证。目前我有两组字段,显示取决于上一个下拉列表的值。即如果下拉列表设置为值A,则表单中将出现一个新字段。如果下拉列表设置为值B,则以形式显示新的字段(当选择A时,与新表单字段互斥)。目前,我的Dojo客户端验证失败,因为未向用户显示的字段(因此没有数据可以插入到这些字段中)无法验证。

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.

目前我确定我可以设置validate属性返回true,如下所示:

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.">

这将修复我隐藏字段的问题。然而,这意味着当该字段对用户可见时,不会执行验证(即,validate属性仍设置为返回true)。

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','');

这只是将属性设置为空,但是在firebug中会出现错误验证方法未找到,所以我认为这意味着我没有正确删除此属性或删除此属性不是这样做的适当方式。

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.

我也看过在覆盖验证器方法这里,但这似乎也不是我想要的。我不哇不需要重写所有的验证方法来代替dojo的。

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.

我只是希望dojo不会验证该字段对用户不可见。感谢任何建议或帮助。

I just want dojo not to validate if the field is not visible to the user. Thanks for any advice or help.

推荐答案

我确定我这样做不正确。 'validate'和'validator'不是dojo ValidationTextBox的适当属性。他们都在Firebug中抛出错误,形式为this.validate不是一个功能。所以起初它看起来像是在为我工作,因为它不再是试图验证字段,但这只是因为错误被抛出。

I 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.

更好解决方案是在加载时将必需属性设置为false。

A better solution was to set the "required" attribute to false upon load.

<input type="text" id="companycode" name="companycode" class="textinput" value="<?php echo set_value('companycode'); ?>" style="<?php if(isset($errorData['companycode'])){echo $errorData['companycode'];} ?>"
            dojotype="dijit.form.ValidationTextBox"
            required="false" trim="true" 
            regexp="(^[A-Za-z]{2}-[0-9]{5}$)"
            invalidMessage="Invalid value.  Must be a valid company code of the form EX-00000">

然后当字段变为可见时,将必需属性设置为true。

Then when a field became visible, set the required attribute back to true.

dijit.byId('companycode').required = true

这篇关于禁用某些字段上的Dojo验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆