我尝试使用带有isEmailAddress验证程序的dijit / form / ValidationTextBox来检查有效的电子邮件,问题是有效的电子邮件被标记为无效。
注意我通过包含" dojox / validate / web"来获得验证器工作,但表单总是在我的登录功能中评估为无效
我的代码是: HTML:
<form data-dojo-type="dijit/form/Form" id="FormLogin">
...
<input type="text" required="true" name="email" data-dojo-attach-point="tbEmail"
data-dojo-type="dijit/form/ValidationTextBox"
validator="dojox.validate.isEmailAddress"
invalidmessage="Not a valid email" />
<button data-dojo-type="dijit/form/Button" type="button"
data-dojo-attach-point="LogInButton" data-dojo-attach-event="onClick:Login">
Login
</button>
...
</form>
JavaScript的:
define([
"dojo/_base/declare",
"dijit/Dialog",
"dijit/form/Form",
"dijit/registry",
"dijit/form/ValidationTextBox",
"dojox/validate",
"dojox/validate/web",
"dijit/_WidgetBase",
"dijit/_TemplatedMixin",
"dijit/_WidgetsInTemplateMixin",
"dojo/text!Templates/LoginForm.htm"
], function (
declare, Dialog, Form, registry, ValidationTextBox, validate, web, _WidgetBase, _TemplatedMixin,
_WidgetsInTemplateMixin, LoginFrmTpl) {
return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], {
templateString: LoginFrmTpl,
postCreate: function () {
},
Login: function () {
if (registry.byId("FormLogin").validate == true) { //this never evaluates to true, even when the email is valid
alert("we can submit the data")
}
else {
alert("error in form")
}
}
});
});
有什么想法吗?无论在tbEmail中输入什么文本
,都会显示无效消息由于
答案 0 :(得分:0)
我通过验证文本框tbEmail来实现它。我将登录功能更改为以下内容:
Login: function () {
if (registry.byId("tbEmail").isValid() == true) {
alert("we can submit the data")
}
else {
alert("error in form")
}
}