2015-12-07 39 views
0

我想用isJmailAddress驗證程序來檢查有效的電子郵件使用dijit/form/ValidationTextBox,問題是有效的電子郵件被標記爲無效。dojox電子郵件驗證程序總是失敗

注意,我得到了驗證通過包括「DojoX中/驗證/網絡」的工作,但形式總是爲無效在我的登錄功能

我的代碼是: 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

完全隨機的猜測,嘗試'.validate()' –

+0

拋出一個錯誤:dojox.validate不是一個函數 – pvitt

+0

你能告訴你更多的javascript?加載頁面時控制檯中是否有錯誤? – Richard

回答

0

我把它通過驗證文本框tbEmail工作。我改變了我的登錄功能,如下:

Login: function() { 
      if (registry.byId("tbEmail").isValid() == true) { 
       alert("we can submit the data") 
      } 
      else { 
       alert("error in form") 
      } 
     }