-
9 May 2009 2:21 AM #11
What do you want to validate if blank is allowed(1)? Against regex or maxLength? I think only this.validate is reasonable.
Adding another option will be ambiguous cause what will this mean:
allowBlank in my opinion is clear. Blank is allowed or not.Code:this.allowBlank = true; this.blankValid = false; // or this.allowBlank = false; this.blankValid = true;
-
9 May 2009 2:42 AM #12Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
It not only needs to check validate, but also vtype (e.g. for vtype:'password' blank is only valid when the original password is also valid).
But I agree that adding another config option (blankValid, default true) would be a better (and Ext 2.x compatible) solution:
Code:Ext.override(Ext.form.TextField, { blankValid : true, validateValue : function(value){ if(value.length < 1 || value === this.emptyText){ if(!this.allowBlank){ this.markInvalid(this.blankText); return false; } if(this.blankValid){ this.clearInvalid(); return true; } } 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 < 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; } });
-
9 May 2009 2:57 AM #13
I really hope that makes it to the next release, because it works like a charm

Thanks Condor!
-
9 May 2009 4:03 AM #14
And what with validators precedence?
Why length is validated after regex? Why we should call this.validate (may be expensive call: dom access, for loops or somethig) if format is wrong?
So in your proposition if I set:
It will mark and then unmark my field? Hm.Code:this.allowBlank = false; this.blankValid = true;
My proposition is 2.2.x compatible. (Tested)
And any password validator could set and unset the allowBlank flag.
PS: Where I can find code of vtype:'password'?
-
9 May 2009 4:42 AM #15Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- The Netherlands
- Posts
- 24,251
- Vote Rating
- 41
I am assuming that almost all fields have either:
1. a validator function
2. a vtype
3. other field settings
but not a combination of the above.
This makes the validation order not really relevant.
Setting allowBlank:false makes the setting of blankValid irrelevant. Blank is always invalid.
The password and daterange vtypes can be found in examples/form/adv-vtypes.js.
-
3 Jun 2009 12:59 PM #16
Marking this thread as [DUP] in favor of the more recent thread here:
http://extjs.com/forum/showthread.ph...822#post335822
The linked thread also links back to this thread.MJ
API Search || Ext 3: docs-demo-upgrade guide || User Extension Repository
Frequently Asked Questions: FAQs
Tutorial: Grid (php/mysql/json) , Application Design and Structure || Extensions: MetaGrid, MessageWindow
-
18 Jun 2009 7:34 AM #17
The behavior has been changed in Ext 3.0 as of revision 4467 (Post RC2) to run the validators in validateValue in the following order:
validator, allowBlank, minLength, maxLength, vtype then regex
http://extjs.com/forum/showthread.php?t=69859&p=345729Aaron Conran
@aconran
Sencha Architect Development Team
Thank you for reporting this bug. We will make it our priority to review this report.



Reply With Quote