-
22 Oct 2012 9:08 AM #1
[4.1.2] TextField ignores VType validation if no value
[4.1.2] TextField ignores VType validation if no value
REQUIRED INFORMATION
Ext version tested:- Ext 4.1.2
- IE9
- Chrome
- <!DOCTYPE html>
- TextField ignores VType validation if no value.
- Yes, I can use allowBlank, but it is not an option, because I need to provide some custom "allowBlank" validation.
- Click the Button
- The field is invalid according VType validation
- The field is valid
Code:<!DOCTYPE html> <html> <head> <title>TextField VType is ignored if no value</title> <link type="text/css" rel="stylesheet" href="../resources/css/ext-all.css" /> <script type="text/javascript" src="../ext-all-debug.js"></script> <script type="text/javascript"> Ext.apply(Ext.form.field.VTypes, { myvtype: function () { return false; } }); Ext.onReady(function () { Ext.create("Ext.form.field.Text", { id: "field1", renderTo: Ext.getBody(), vtype: "myvtype" }); Ext.create("Ext.button.Button", { renderTo: Ext.getBody(), text: "isValid", handler: function () { alert(Ext.getCmp("field1").isValid()); } }); }); </script> </head> <body> </body> </html>
-
22 Oct 2012 12:27 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 438
This is a fundamental change. On one had I would agree but on the other hand there is no value to validate against and this is what allowBlank is for.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
22 Oct 2012 4:32 PM #3
This is by design. The validator function trumps everything. If the value is blank, and we've got allowBlank, then it just jumps out.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
-
22 Oct 2012 9:17 PM #4
Hi Mitchell and Evan,
Thank you for the answers.
Yes, I understand that it is by design and it is a big deal to change.
I am just drawing your attention to this problem. Maybe, the chosen design was not the best one. Personally, I would not ignore VType (and validator as well) if no value. It would allow to clearly accomplish, for example, a common task to validate a field for password confirmation.
Now our "password" VType looks:
Everything is good except a case when a field is empty.Code:password : function (val, field) { if (field.initialPassField) { var pwd = Ext.getCmp(field.initialPassField); return pwd ? (val === pwd.getValue()) : false; } return true; }, passwordText : "Passwords do not match"
I think there can be many other scenarios where we need "allowBlank" validation according some external condition (like in my case - 'if a primary password field is not empty').
Yes, there is a simple workaround - listen the "change" event of the primary password field to set allowBlank to true for the secondary password field. But it is a trick.
-
26 Oct 2012 9:59 AM #5
This makes it invalid
Code:Ext.apply(Ext.form.field.VTypes, { myvtype: function () { return false; } }); Ext.onReady(function () { Ext.create("Ext.form.field.Text", { id: "field1", renderTo: Ext.getBody(), validator: function() { return false; } }); Ext.create("Ext.button.Button", { renderTo: Ext.getBody(), text: "isValid", handler: function () { alert(Ext.getCmp("field1").isValid()); } }); });Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
28 Oct 2012 9:55 AM #6
-
28 Oct 2012 12:37 PM #7
This is a discussion which has been had here many times.
The allowBlank flag functions as a "blankAlwaysValid" flag.
See this from 2008: http://www.sencha.com/forum/showthre...llowBlank-set&
It's just established in the API.
We could probably have another flag which decides whether it means blank should bypass all other validation which would be true by default to maintain behaviour.Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
28 Oct 2012 12:45 PM #8
Thanks for the report! I have opened a bug in our bug tracker.
We need to make this flexible so that people can apply validation to blank values!
-
30 Oct 2012 2:21 AM #9
That is great! Thank you, @Animal!
It would be very nice if you could look at this issue.
http://www.sencha.com/forum/showthread.php?242897
It is a very severe issue for our toolkit based on ExtJS.
(Apologize for a trick. Please ignore if you wish.)
-
13 Mar 2013 10:02 PM #10
Success! Looks like we've fixed this one. According to our records the fix was applied for
EXTJSIV-7625
in
4.2.


Reply With Quote