Extjs4 - 远程验证 [英] Extjs4 - remote validation

查看:140
本文介绍了Extjs4 - 远程验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个文本框的远程验证器。我的PHP返回true / false值。我已经尝试过这样的事情:

  {
xtype:'textfield',
fieldLabel:'字段',
allowBlank:false,
验证器:function(value){
Ext.Ajax.request({
url:'psc / validate',
params :{psc:value},
success:function(response){
return response.responseText
}
});
});
}

问题是ajax请求是asynchonous,验证器给出未定义的值错误。有回调吗?所以我默认返回false,一旦ajax调用完成,使textfield有效。



我尝试使用google进行远程验证,但没有太多的限制。



还是建议?谢谢。

解决方案

也许你不应该使用验证器,然后在文本框中添加更改列表,并使用方法markInvalid和clearInvalid显示验证。

  {
xtype:'textfield',
fieldLabel:'Field',
allowBlank:false,
textValid:false,
验证器:function(){
return this.textValid;
},
listeners:{
'change':function(textfield,newValue,oldValue){
Ext.Ajax.request({
url:'psc /验证',
参数:{psc:value},
范围:textfield,
success:function(response){
if(response.responseText){
this .clearInvalid();
this.textValid = true;
} else {
this.markInvalid('field is not valid');
this.textValid = false;
}
}
});
}
}
}

我没有试过但是可以为您的aproach工作



编辑我已经对代码进行了一些修改以包含验证器..


I'd like having a remote validator for a textfield. My PHP returns true/false value. I've tried something like this:

{
   xtype: 'textfield',
   fieldLabel: 'Field',
   allowBlank: false,
   validator : function(value) {
      Ext.Ajax.request({
      url: 'psc/validate',
      params: { psc: value },
      success: function(response){
       return response.responseText                             
      }
      });
   });
}

The problem is that ajax request is asynchonous and the validator gives "values not defined" error. Is there any callback? So I would return false by default and make textfield valid once ajax call would be finished.

I've tried to google for extjs remote validation but there is not much about it.

Anybody help or suggestions? Thanks.

解决方案

maybe you shouldnt use the validator then, add a listner on change for the textfield and use the methods markInvalid and clearInvalid for displaying the validation.

{
   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;
             }                             
          }
        });
      }       
   }
}

I haven;t tried it but could work for your aproach

EDIT i've made some modifications to the code to include the validator..

这篇关于Extjs4 - 远程验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆