日期:2014-05-16 浏览次数:20522 次
Ext.apply(Ext.form.VTypes, {
repetition: function(val, field) {
//代码逻辑在此
},
repetitionText: '两个指定组件的组件值不一样'
}) Ext.apply(Ext.form.VTypes, {
repetition: function(val, field) { //返回true,则验证通过,否则验证失败
if (field.repetition) { //如果表单有使用repetition配置,repetition配置是一个JSON对象,该对象提供了一个名为targetCmpId的字段,该字段指定了需要进行比较的另一个组件ID。
var cmp = Ext.getCmp(field.repetition.targetCmpId); //通过targetCmpId的字段查找组件
if (Ext.isEmpty(cmp)) { //如果组件(表单)不存在,提示错误
Ext.MessageBox.show({
title: '错误',
msg: '发生异常错误,指定的组件未找到',
icon: Ext.Msg.ERROR,
buttons: Ext.Msg.OK
});
return false;
}
if (val == cmp.getValue()) { //取得目标组件(表单)的值,与宿主表单的值进行比较。
return true;
} else {
return false;
}
}
},
repetitionText: '两个指定组件的组件值不一样'
}) new Ext.form.FieldSet({
title: '注册信息',
autoHeight: true,
checkboxToggle: true,
labelWidth: 55,
items: [
new Ext.form.TextField({
fieldLabel: 'Email',
vtype: 'email'
}),
new Ext.form.TextField({
inputType: 'password',
id: 'pass1',
maxLength: 6,
fieldLabel: '输入密码',
allowBlank: false
}),
new Ext.form.TextField({
inputType: 'password',
id: 'pass2',
maxLength: 6,
fieldLabel: '重复密码',
allowBlank: false,
vtype: 'repetition', //指定repetition验证类型
repetition: { targetCmpId: 'pass1' } //配置repetition验证,提供目标组件(表单)ID
})
]
})
