我正在学习Ext JS 5.1 是否可以从View中调用ViewController中定义的验证方法?
MyView的
{
xtype: 'textfield',
margin: '0 0 10 0',
fieldLabel: 'Password',
name: 'pass1',
reference: 'pass1',
inputType: 'password',
allowBlank: false,
minLength: 5
},
{
xtype: 'textfield',
margin: '0 0 10 0',
fieldLabel: 'Confirm Password',
name: 'pass2',
reference: 'pass2',
inputType: 'password',
allowBlank: false,
validator: 'checkPassword' // want to call method that defined in ViewController
}
MyViewController
checkPassword: function(value){
var pass1val = this.lookupReference('pass1').getValue();
if (value == pass1val){
return true;
}
else{
return "The initial password and the re-typed password do not match.";
}
}
答案 0 :(得分:2)
我目前对v5.1的解决方法如下(示例here):
// ...in ViewController
init: function() {
var startCombo = this.lookupReference('startCombo');
var endCombo = this.lookupReference('endCombo');
startCombo.validator = Ext.bind(this.comboValidator, this, [startCombo, endCombo]);
endCombo.validator = Ext.bind(this.comboValidator, this, [startCombo, endCombo]);
},
comboValidator: function(startCombo, endCombo) {
return startCombo.getValue() < endCombo.getValue();
},
答案 1 :(得分:1)
目前,你不能。但你应该能够。我会记录一张票来解决这个问题。