In my example below I'm using a dijit.form.DateTextBox
:
在我下面的例子中,我使用的是dijit.form.DateTextBox:
<input type="text" name="startDate" dojoType="dijit.form.DateTextBox" constraints="{datePattern:'MM/dd/yyyy'}" value='<c:out value="${sessionScope.adminMessageForm.startDate}"/>' />
So for example, if the user starts to enter "asdf" into the date the field turns yellow and a popup error message appears saying The value entered is not valid.
. Even if I remove the constraints="{datePattern:'MM/dd/yyyy'}"
it still validates.
因此,例如,如果用户开始在日期中输入“asdf”,则字段变为黄色,并显示弹出错误消息,说明输入的值无效..即使我删除约束=“{datePattern:'MM / dd / yyyy'}“它仍然有效。
Without going into details as to why, I would like to be able keep the dojoType and still prevent validation in particular circumstances.
在不详细说明原因的情况下,我希望能够保留dojoType并在特定情况下仍然阻止验证。
3 个解决方案
#1
6
Try overriding the validate method in your markup.
尝试覆盖标记中的validate方法。
This will work (just tested):
这将工作(刚刚测试):
<input type="text" name="startDate" dojoType="dijit.form.DateTextBox"
constraints="{datePattern:'MM/dd/yyyy'}"
value='<c:out value="${sessionScope.adminMessageForm.startDate}"/>'
validate='return true;'
/>
#2
1
My only suggestion is to programmatically remove the dojoType on the server-side or client-side. It is not possible to keep the dojoType and not have it validate. Unless you create your own type that has you logic in it.
我唯一的建议是以编程方式删除服务器端或客户端的dojoType。不可能保留dojoType而不进行验证。除非您创建自己的类型,其中包含您的逻辑。
#3
1
I had a similar problem, where the ValidationTextBox met all my needs but it was necessary to disable the validation routines until after the user had first pressed Submit.
我遇到了类似的问题,ValidationTextBox满足了我的所有需求,但是必须先禁用验证例程,直到用户第一次按下Submit。
My solution was to clone this into a ValidationConditionalTextBox with a couple new methods:
我的解决方案是使用几个新方法将其克隆到ValidationConditionalTextBox中:
enableValidator:function() {
this.validatorOn = true;
},
disableValidator: function() {
this.validatorOn = false;
},
Then -- in the validator:function() I added a single check:
然后 - 在验证器:function()中我添加了一个检查:
if (this.validatorOn)
{ ... }
Fairly straightforward, my default value for validatorOn is false (this appears right at the top of the javascript). When my form submits, simply call enableValidator(). You can view the full JavaScript here:
相当简单,我的validatorOn的默认值是false(这显示在javascript的顶部)。当我的表单提交时,只需调用enableValidator()。您可以在此处查看完整的JavaScript:
http://lilawnsprinklers.com/js/dijit/form/ValidationTextBox.js
#1
6
Try overriding the validate method in your markup.
尝试覆盖标记中的validate方法。
This will work (just tested):
这将工作(刚刚测试):
<input type="text" name="startDate" dojoType="dijit.form.DateTextBox"
constraints="{datePattern:'MM/dd/yyyy'}"
value='<c:out value="${sessionScope.adminMessageForm.startDate}"/>'
validate='return true;'
/>
#2
1
My only suggestion is to programmatically remove the dojoType on the server-side or client-side. It is not possible to keep the dojoType and not have it validate. Unless you create your own type that has you logic in it.
我唯一的建议是以编程方式删除服务器端或客户端的dojoType。不可能保留dojoType而不进行验证。除非您创建自己的类型,其中包含您的逻辑。
#3
1
I had a similar problem, where the ValidationTextBox met all my needs but it was necessary to disable the validation routines until after the user had first pressed Submit.
我遇到了类似的问题,ValidationTextBox满足了我的所有需求,但是必须先禁用验证例程,直到用户第一次按下Submit。
My solution was to clone this into a ValidationConditionalTextBox with a couple new methods:
我的解决方案是使用几个新方法将其克隆到ValidationConditionalTextBox中:
enableValidator:function() {
this.validatorOn = true;
},
disableValidator: function() {
this.validatorOn = false;
},
Then -- in the validator:function() I added a single check:
然后 - 在验证器:function()中我添加了一个检查:
if (this.validatorOn)
{ ... }
Fairly straightforward, my default value for validatorOn is false (this appears right at the top of the javascript). When my form submits, simply call enableValidator(). You can view the full JavaScript here:
相当简单,我的validatorOn的默认值是false(这显示在javascript的顶部)。当我的表单提交时,只需调用enableValidator()。您可以在此处查看完整的JavaScript:
http://lilawnsprinklers.com/js/dijit/form/ValidationTextBox.js