Extjs4 - remote validation

前端 未结 2 1109
逝去的感伤
逝去的感伤 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

    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..

提交回复
热议问题