-
21 Sep 2012 12:27 PM #1
BUG: Ext.data.Types BOOL is casesensitive
BUG: Ext.data.Types BOOL is casesensitive
Models that include 'boolean' fields are either required to provide all lowercase boolean strings OR to write a convert() function for every field that uses boolean in their Model declarations.
Here's the relevant snippet from Ext.data.Types
Code:BOOL: { convert: function(v) { if (this.useNull && (v === undefined || v === null || v === '')) { return null; } return v === true || v === 'true' || v == 1; }, sortType: st.none, type: 'bool'
I think it would be more intuitive if it did more like:
No?Code:BOOL: { convert: function(v) { if (this.useNull && (v === undefined || v === null || v === '')) { return null; } return Boolean(v); }, sortType: st.none, type: 'bool'
-
23 Sep 2012 4:39 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,641
- Vote Rating
- 434
Boolean(v) won't work because this would return true:
Now the v === 'true' could be:Code:Boolean('I should be false')
And that would be case-insensitiveCode:/true/i.test(v)
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.
-
23 Sep 2012 5:19 AM #3
You're right (of course)
But the fact that the current incarnation is case sensitive makes this a bit cumerbsome. For example, we have a model associated with an Ajax proxy. The server in this case is returning 'True' for its booleans. It means everywhere we use 'boolean' in our extjs model's, we need to add a covert() method for each individual field that coerces to lowercase.
Of course, we could probably create our own Ext.type.Type for something like CSBOOL -- but we use Sencha Architect for our coding activity -- and I'm not sure if we'd be able to refer to this custom type from SA.
It seems to me that it would make syntactic sense to modify the base type, no?
-
23 Sep 2012 11:48 PM #4
This isn't a bug, the docs are clear on what the bool type will convert automatically. The overhead of doing a case insensitive comparison isn't worth it for the small use case, especially since you can create your own types quite easily.
Evan Trimboli
Sencha Developer
Twitter - @evantrimboli
Don't be afraid of the source code!
Looks like we can't reproduce the issue or there's a problem in the test case provided.


Reply With Quote