PDA

View Full Version : Problem to validate using vtype



cfhank
4 Jun 2009, 5:48 AM
Because the version 3 when I add:
vtype: 'email'

it requires the field to enter the email, is to remove it, even if I add the:
allowBlank: false

does not work.

aconran
4 Jun 2009, 8:02 AM
There were some behavior changes with allowBlank. We are currently invesitgating these changes to see how they are affecting developers in their applications.

Could you explain waht type of behavior you desire and how Ext is not working as you expect it to?

cfhank
4 Jun 2009, 8:11 AM
example:

if I define a field in the: vtype: 'email', when I send the order form it requires the field of email, but I do not oblige the user to inform the email.

aconran
4 Jun 2009, 9:04 AM
Hrm, don't you want allowBlank: true?

cfhank
4 Jun 2009, 9:12 AM
even if I define "allowBlank: true" does not work

aconran
4 Jun 2009, 9:43 AM
Please give us details of the configuration options you are using and your expected behavior and use case.

Thanks,

cabal
5 Jun 2009, 6:17 AM
The reason of this behaviour is new validation order [as written in api doc, Ext.form.TextField, and also http://extjs.com/forum/showthread.php?t=70352&highlight=allowBlank] (http://extjs.com/forum/showthread.php?t=70352&highlight=allowBlank%5D)
Build-in validation (allowBlank) is the 4th step, should first.
If field is blank and allowBlank is true or undefined [as in 2.x] the validation process should not be continued - field is ok.

cfhank
5 Jun 2009, 6:52 AM
tanks cabal,
to resolve the issue here did the following:

file: ext-all-debug.js


old:

validateValue : function(value){
if(Ext.isFunction(this.validator)){
var msg = this.validator(value);
if(msg !== true){
this.markInvalid(msg);
return false;
}
}
if(this.vtype){
var vt = Ext.form.VTypes;
if(!vt[this.vtype](value, this)){
this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
return false;
}
}
if(this.regex && !this.regex.test(value)){
this.markInvalid(this.regexText);
return false;
}
if(value.length < 1 || value === this.emptyText){ // if it's blank
if(this.allowBlank){
this.clearInvalid();
return true;
}else{
this.markInvalid(this.blankText);
return false;
}
}
if(value.length < this.minLength){
this.markInvalid(String.format(this.minLengthText, this.minLength));
return false;
}
if(value.length > this.maxLength){
this.markInvalid(String.format(this.maxLengthText, this.maxLength));
return false;
}
return true;
},


new:

validateValue : function(value){
if(Ext.isFunction(this.validator)){
var msg = this.validator(value);
if(msg !== true){
this.markInvalid(msg);
return false;
}
}
if(this.regex && !this.regex.test(value)){
this.markInvalid(this.regexText);
return false;
}
if(value.length < 1 || value === this.emptyText){ // if it's blank
if(this.allowBlank){
this.clearInvalid();
return true;
}else{
this.markInvalid(this.blankText);
return false;
}
}
if(value.length < this.minLength){
this.markInvalid(String.format(this.minLengthText, this.minLength));
return false;
}
if(value.length > this.maxLength){
this.markInvalid(String.format(this.maxLengthText, this.maxLength));
return false;
}
if(this.vtype){
var vt = Ext.form.VTypes;
if(!vt[this.vtype](value, this)){
this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
return false;
}
}
return true;
},

cfhank
5 Jun 2009, 7:01 AM
oder, file bugs.js:


if(Ext.form.TextField){
Ext.apply(Ext.form.TextField.prototype, {
validateValue : function(value){
if(Ext.isFunction(this.validator)){
var msg = this.validator(value);
if(msg !== true){
this.markInvalid(msg);
return false;
}
}
if(this.regex && !this.regex.test(value)){
this.markInvalid(this.regexText);
return false;
}
if(value.length < 1 || value === this.emptyText){ // if it's blank
if(this.allowBlank){
this.clearInvalid();
return true;
}else{
this.markInvalid(this.blankText);
return false;
}
}
if(value.length < this.minLength){
this.markInvalid(String.format(this.minLengthText, this.minLength));
return false;
}
if(value.length > this.maxLength){
this.markInvalid(String.format(this.maxLengthText, this.maxLength));
return false;
}
if(this.vtype){
var vt = Ext.form.VTypes;
if(!vt[this.vtype](value, this)){
this.markInvalid(this.vtypeText || vt[this.vtype +'Text']);
return false;
}
}
return true;
}
});
}