网站需要两次密码验证,vtype当然是最方便的方法但是只有一个页面的验证正确,代码如下:
/*
*密码修改
*resetpwdWin 密码显示框
*resetpwdForm 密码修改form
*/
var resetpwdForm = new Ext.form.FormPanel({
labelAlign:'left',
labelWidth:60,
width:260,
border:false,
bodyStyle:'top:15px;left:20px',
defaultType:'textfield',
items:[{
fieldLabel : '新密码',
inputType : 'password',
width : 120,
itemId : 'pwd',
allowBlank : false,
name : 'pwd',
id:'pwd',
minLength : 5,
msgTarget:'side',
maxLength : 32,
blankText:'输入密码只能在5-32字符之间'
},{
fieldLabel : '确认密码',
inputType : 'password',
width : 120,
itemId : 'pwd2',
allowBlank : false,
name : 'pwd2',
msgTarget:'side',
vtype:'password',
confirmTo:'pwd',
vtypeText:'两次密码不一致',
blankText:'确认密码项不能为空'
}]
})
//添加自定义函数
var resetpwdWin = new Ext.Window({
width:260,
height:150,
title:'密码修改',
closeAction:'hide',
buttonAlign:'center',
layout:'fit',
bodyStyle:'background-color:#fff;',
items:resetpwdForm,
buttons:[{
text:'保存修改',
handler:function(){
if(resetpwdForm.getForm().isValid()){
Ext.Ajax.request({
url:'user!updatePwd.action',
params:{
'newPassword':resetpwdForm.getForm().findField("pwd").getValue()
},
success:function(response){
var newJson=Ext.decode(response.responseText);
if(newJson.success){
Ext.MessageBox.show({title:'提示',msg:'密码修改成功'});
}else{
Ext.MessageBox.show({title:'提示',msg:'密码修改失败'});
}
resetpwdWin.hide();
}
})
}
}
},{
text:'取消',
handler:function(){
resetpwdWin.hide();
}
}]
})
其他页面会出现
这个错误,真是让我纠结,网上好像也没有人遇到过这个问题,我猜测不会是第二次使用出现的问题吧。
根据问题的提示,应该是说vtype的类型不正确,所以我自定义了password的方法,代码如下:
/**
* 用Ext.apply方法添加自定义的password验证函数
*/
Ext.apply(Ext.form.VTypes,{
password:function(val, field) { //val:这个文本框的值,field:这个文本框组件
if(field.confirmTo) { //confirmTo是自定义的配置参数,一般用来保存另外的组件的id值
var pwd = Ext.getCmp(field.confirmTo); //取得confirmTo的那个id的值
return(val == pwd.getValue());
}
return false;
}
});
问题得到解决。不过我依然不知道为什么会有这个问题,不知道有谁能帮我解答?是ext的问题么?