Extjs4 - remote validation

前端 未结 2 1137
逝去的感伤
逝去的感伤 2021-02-15 04:50

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:          


        
2条回答
  •  旧巷少年郎
    2021-02-15 05:18

    {
     fieldLabel : 'Username',
     name : 'username',
     allowBlank : false,
     validFlag : true,
     validator : function() {
      return this.validFlag;
     },
     listeners : {
      'change' : function(textfield, newValue, oldValue) {
       var me = this;
       Ext.Ajax.request({
        url : 'rest/users?action=validate&username=' + newValue,
        success : function(response) {
         // Ausuming responseText is {"valid" : true}
         me.validFlag = Ext.decode(response.responseText).valid ? true : 'The username is duplicated!';
         me.validate();
        }
       });
      }
     }
    }

    this html code i tested(extjs version is 5.0) ,is ok ,it is from TonyTuan'sBlog , all of this you can see this link : http://code.tonytuan.org/2013/06/extjs-remote-validator-for-form-field.html

提交回复
热议问题