-
17 Mar 2009 12:58 AM #1
[Sloved][custom Vtype] form is valid if my field is invalid
[Sloved][custom Vtype] form is valid if my field is invalid
hi all
i have writen an custom Vtype that check if an id already exist,the field is properly marked invalid if it is, but my form still validand can be submited.
there is the code of my validator
i check if form is valid before submiting.Code:Ext.apply(Ext.form.VTypes, { duplicateId : function (val, field){ var validfield = true; Ext.Ajax.request({ url:'rh/getdata',method:'POST', async : false, params :{gData:'ifExist',matricule: val }, success: function(responseObject){ var resp = responseObject.responseText; if (resp == 1) { validfield=false; field.markInvalid('Ce matricule est déja attribué à un employé !'); } else if (resp == 0) { validfield=true; field.clearInvalid(); }}, failure: function(){return false}}); return validfield; } });
Code:submit : function () { if (this.getForm().isValid()) { this.getForm().submit({ url: 'rh/setdata', waitMsg: 'Enregistrement en cours...', scope : this, method: 'POST', success:this.onSuccess, failure:this.onFailure, params: { gData : 'saveEmploye', newEmp:this.nouvEmp // matricule:idadds }})} else {this.showError('Veuillez completer votre formulaire','erreur');} }I have certainly omitted somethingnewbie with ExtJS.
visit my Blog (use Zend Framework with ExtJS)
-
17 Mar 2009 1:17 AM #2
Code:Ext.apply(Ext.form.VTypes, { duplicateId: function(val, field) { var validfield = true; Ext.Ajax.request({ url: 'rh/getdata', method: 'POST', async: false, params: { gData: 'ifExist', matricule: val }, success: function(responseObject) { var resp = responseObject.responseText; if (resp == 1) { validfield = false; field.markInvalid('Ce matricule est déja attribué à un employé !'); } else if (resp == 0) { validfield = true; field.clearInvalid(); } }, failure: function() { return false } }); return validfield;// this cause your request valid. because since request ajax so at at that time //we can not say whether the request is success or failure } });Shibu Bhattarai
Use JavaScript beautifier to beautify you code http://jsbeautifier.org/
Code Conventions http://javascript.crockford.com/code.html
ExtJS Core Manual http://extjs.com/products/extcore/manual/
-
17 Mar 2009 2:15 AM #3
tanks it's work, soleved
newbie with ExtJS.
visit my Blog (use Zend Framework with ExtJS)


Reply With Quote
