在我的Dijit表单中,我有以下ValidationTextBox:
<input data-dojo-type="dijit/form/ValidationTextBox"
name="email" data-dojo-props="required: true,
validator:dojox.validate.isEmailAddress,
invalidMessage: 'Invalid email'" />
但是,我想要使字段不(即允许它为空),但仍然使用dojox.validate方法。删除required: true
或明确设置required: false
似乎无效;该字段仍然显示&#34;无效的电子邮件。&#34;如果文本存在,我怎么才能使用验证方法?
答案 0 :(得分:3)
编写自己的验证器并设置required = false,如下所示:
<input data-dojo-type="dijit/form/ValidationTextBox"
name="email" data-dojo-props="required: false,
validator: function(text){
if (!text){
return true;
}
return dojox.validate.isEmailAddress(text);
},
invalidMessage: 'Invalid email'" />