【问题标题】:Extjs Confirm PasswordExtjs 确认密码
【发布时间】:2012-01-19 17:36:39
【问题描述】:

我有两个密码字段,并在允许发布之前尝试确认它们相同。这是我的代码,它返回“密码不匹配!”每次都不管。当我在我的var pass1 = ... 行之后执行alert(pass1) 时,它给了我undefined。我也试过var pass1 = formPanel.findField("txt_newPIN").getValue(),它返回同样的东西。代码如下:

    {
    fieldLabel:"PIN/Password",
    actionText:"Edit",
    fieldValue:"****",
    dialog:new MyAccount.DialogBox({
        id:"win_editPIN",
        name:"editPIN",
        headerContent:"Edit Password:",
        updateURL:"/uiapi/myaccount/setAccountPIN",
        items:[{
            id:"txt_currentPIN",
            name: "currentPIN",
            fieldLabel: "Current Password",
            validationEvent:"blur",
            allowBlank: false,
            maxLength:20,
            inputType:"password"
        },{
            id:"txt_newPIN",
            name: "newPIN",
            fieldLabel: "New Password",
            vtype:"confirmPassword",
            validationEvent:"blur",
            allowBlank: false,
            maxLength:20,
            inputType:"password"
        },{
            id:"txt_confirmPIN",
            fieldLabel: "Confirm Password",
            vtype:"confirmPassword",
            validationEvent:"blur",
            initialPin:"txt_newPIN",
            allowBlank: false,
            maxLength:20,
            inputType:"password"
        }], 


 validateForm:function() {
     var formPanel = Ext.getCmp("win_editPIN").formPanel.getForm();
         // Save the fields we are going to insert values into
         var pass1 = formPanel.findField("txt_newPIN");
     var pass2 = formPanel.findField("txt_confirmPIN");

         if (pass1 != pass2)
             return {success:false,  errorMessage:"Passwords do not match!"}
         }

    })

【问题讨论】:

    标签: validation passwords extjs confirm


    【解决方案1】:

    感谢 Nghia,您的回答让我成功了一半,让我可以选择字段。剩下的就是制作一个自定义的validator 选项,这里是代码,为简洁起见只显示最后一项。

         {
                id:"txt_confirmPIN",
                name: "newPIN_confirm",
                fieldLabel: "Confirm Password",
                validationEvent:"blur",
                initialPin:"txt_newPIN",
                allowBlank: false,
                maxLength:20,
                inputType:"password",
                // This custom validator option expects a return value of boolean true if it
                // validates, and a string with an error message if it doesn't
                validator: function() {
                       var formPanel = Ext.getCmp("win_editPIN").formPanel.getForm();
                       // Save the fields we are going to insert values into
                       var pass1 = Ext.getCmp('txt_newPIN').getValue();
                       var pass2 = Ext.getCmp('txt_confirmPIN').getValue();
                       console.log("pass 1 = " + pass1 + "--pass 2 = " + pass2);
    
                        if (pass1 == pass2)
                            return true;
    
                        else 
                            return "Passwords do not match!";
                }
            }
    

    如果验证,此验证器选项期望返回值 true,如果不验证,则返回带有错误消息的字符串。

    【讨论】:

      【解决方案2】:

      使用 findField() 方法时需要传递字段名称而不是字段 ID。

      var pass1 = formPanel.findField("newPIN");
      

      或者直接获取它的值

      var pass1 = Ext.getCmp('txt_newPIN').getValue();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-23
        • 1970-01-01
        • 1970-01-01
        • 2013-09-18
        • 2015-04-03
        • 2023-02-23
        相关资源
        最近更新 更多