2015-12-31 116 views
0

我在視圖中執行驗證時遇到了一些問題。在移動應用程序中驗證

我正在嘗試關注網站中的其中一個Devextreme示例。 http://js.devexpress.com/Demos/WidgetsGallery/#demo/editors-validation-overview

錯誤什麼,我得到的是「遺漏的類型錯誤:無法讀取屬性未定義‘驗證’」。同時點擊完成按鈕。

這是我在用代碼:` 用戶名: 密碼: 重新輸入密碼:

PaMobile01.popup = function (params, viewInfo) { 
"use strict"; 

var openTabsAsRoot = viewInfo.layoutController.name === "split", 
    isReady = $.Deferred(); 



function handleViewShown() { 
    loadopetions(); 
} 


function validateAndSubmit(params) { 
    var result = params.validationGroup.validate(); 
    if (result.isValid) { 
     DevExpress.ui.notify({ 
      message: "You have submitted the form", 
      position: { 
       my: "center top", 
       at: "center top" 
      } 
     }, "success", 3000); 
    } 
} 

function loadopetions() { 
    $("#tbx_userneme").dxTextBox({ 
     placeholder: 'Required', 
    }).dxValidator({ 
     validationRules: [{ 
      type: "required", 
      message: "City is required" 
     }, { 
      type: "pattern", 
      pattern: "^[a-zA-Z]+$", 
      message: "Do not use digits in the City name." 
     }, { 
      type: "pattern", 
      pattern: "^.{2,}$", 
      message: "City must have at least 2 symbols" 
     }] 
    }); 

    $("#tbx_password").dxTextBox({ 
     placeholder: 'Required', 
    }).dxValidator({ 
     validationRules: [{ 
      type: "required", 
      message: "City is required" 
     }, { 
      type: "pattern", 
      pattern: "^[a-zA-Z]+$", 
      message: "Do not use digits in the City name." 
     }, { 
      type: "pattern", 
      pattern: "^.{2,}$", 
      message: "City must have at least 2 symbols" 
     }] 
    }); 

    $("#tbx_repassword").dxTextBox({ 
     placeholder: 'Required', 
    }).dxValidator({ 
     validationRules: [{ 
      type: "required", 
      message: "City is required" 
     }, { 
      type: "pattern", 
      pattern: "^[a-zA-Z]+$", 
      message: "Do not use digits in the City name." 
     }, { 
      type: "pattern", 
      pattern: "^.{2,}$", 
      message: "City must have at least 2 symbols" 
     }] 
    }); 

} 

function handlefinish() { 
    validateAndSubmit(params); 
} 
return { 
    isReady: isReady.promise(), 
    viewShown: handleViewShown, 
    openTabsAsRoot: openTabsAsRoot, 
    handlefinish: handlefinish 
} 

};

回答

1

調用驗證的函數必須接收params參數。看看它是如何在教程中完成的:

$("#button").dxButton({ 
    text: "Submit", 
    type: "success", 
    onClick: validateAndSubmit 
}); 

庫正在處理這個params對象。現在在你的代碼中,你隱藏了圖書館期望的handlefinish這個沒有參數的函數。 您可以添加params作爲參數傳遞給函數定義:

function handlefinish(params) { 
    validateAndSubmit(params); 
} 

或回函數本身:

return { 
    isReady: isReady.promise(), 
    viewShown: handleViewShown, 
    openTabsAsRoot: openTabsAsRoot, 
    validateAndSubmit: validateAndSubmit 
} 

也要看你如何管理模塊PaMobile01.popup功能,儘量按照教程。

UPDATE:

看看在文檔重新輸入密碼驗證:comparerule

根據該文件,你需要一個驗證規則添加到#tbx_repassword驗證: [{ type: 'compare', comparisonTarget: getPassword }]

哪裏getPassword是一個功能,如:

function getPassword(){ 
    return document.getElementById('tbx_password').value; 
} 
+0

嗨我也試過,也是b它也是拋出錯誤「Uncaught TypeError:無法讀取屬性'validate'的validateAndSubmit函數 – vishal

+0

嗨,我現在能夠解決它現在thanx很多你的幫助。 – vishal

+0

目前我正在面對其他兩個dxtextbox值的比較問題。 像上面的代碼中的密碼和reenterpassword一樣。 你能幫我解決這個問題嗎? – vishal

相關問題