got*_*och 8 validation extjs extjs4
我想要一个文本字段的远程验证器.我的PHP返回true/false值.我尝试过这样的事情:
{
xtype: 'textfield',
fieldLabel: 'Field',
allowBlank: false,
validator : function(value) {
Ext.Ajax.request({
url: 'psc/validate',
params: { psc: value },
success: function(response){
return response.responseText
}
});
});
}
Run Code Online (Sandbox Code Playgroud)
问题是ajax请求是异步的,验证器给出"未定义的值"错误.有没有回调?所以我默认会返回false,并且一旦ajax调用完成就使textfield有效.
我试图谷歌进行extjs远程验证,但没有太多关于它.
有人帮忙或建议?谢谢.
nsc*_*rob 11
也许你不应该使用验证器,然后在文本字段的变化上添加一个列表器,并使用方法markInvalid和clearInvalid来显示验证.
{
xtype: 'textfield',
fieldLabel: 'Field',
allowBlank: false,
textValid: false,
validator: function(){
return this.textValid;
},
listeners : {
'change': function(textfield,newValue,oldValue) {
Ext.Ajax.request({
url: 'psc/validate',
params: { psc: value },
scope: textfield,
success: function(response){
if (response.responseText){
this.clearInvalid();
this.textValid = true;
} else {
this.markInvalid('field is not valid');
this.textValid = false;
}
}
});
}
}
}
Run Code Online (Sandbox Code Playgroud)
我没有尝试过,但可以为你的方法工作
编辑我已经对代码进行了一些修改以包含验证器..
| 归档时间: |
|
| 查看次数: |
6543 次 |
| 最近记录: |