-
24 Apr 2012 7:20 PM #1
Select field can't have 0 as value
Select field can't have 0 as value
REQUIRED INFORMATION
Ext version tested:- Sencha Touch 2.0.1
Browser versions tested against:- Safari 5.1.5
DOCTYPE tested against:- html
Description:- If a selectfield has an option whose value is the number 0, and you set the default value of the selectfield to the number 0, the value won't be stored. It won't show any option selected.
Steps to reproduce the problem:- Run the code below
The result that was expected:- The "zero" text appears in the field, and getValue() returns 0.
The result that occurs instead:- The "select one" text appears in the field, and getValue() returns null.
Test Case:
Code:Ext.define('MyForm', { extend: 'Ext.form.Panel', config: { fullscreen: true, items: [{ itemId: 'x', xtype: 'selectfield', placeHolder: 'select one', name: 'x', label: 'x', value: 0, options: [ {text: 'zero', value: 0}, {text: 'one', value: 1} ] }] } }); var form = Ext.create('MyForm');
HELPFUL INFORMATION
Screenshot or Video:- N/A
See this URL for live test case: N/A
Debugging already done:- Works if you use strings, e.g. "0". I'm not sure if integers are allowed as values.
Possible fix:- not provided
Additional CSS used:- only default ext-all.css
Operating System:- Mac OS 10.7.3
-
25 Apr 2012 5:34 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,714
- Vote Rating
- 436
It works if you select one and then select zero but not initial value. Thanks for the report.
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.
-
26 Apr 2012 5:28 AM #3
I had the same issue. Not sure if this was the best way to handle it, but this override worked for me. I only changed the one line where it checks if value is true. It's not true if the value is zero so it looks like that's what's causing the issue.
Code:Ext.define('TP.extend.override.Select', { override: 'Ext.field.Select', applyValue: function(value) { var record = value, index, store; //we call this so that the options configruation gets intiailized, so that a store exists, and we can //find the correct value this.getOptions(); store = this.getStore(); //OVERRIDE NEXT LINE //if ((value && !value.isModel) && store) { if ((value != undefined && value != null && !value.isModel) && store) { index = store.find(this.getValueField(), value, null, null, null, true); if (index == -1) { index = store.find(this.getDisplayField(), value, null, null, null, true); } record = store.getAt(index); } return record; } });
-
29 Apr 2012 7:30 AM #4
Confirming Bug
Confirming Bug
I can confirm the bug and that the FrankK fix works. Using strings and setting the initial value to non zero does not solve the problem.
Thanks to FrankK !
-
29 Apr 2012 4:02 PM #5
There are two bugs here:
1) That which FrankK fixed, where falsey values won't get looked up in the store
2) applyValue and updateValue pass unmatched values through to this.record as-is. getValue has logic to check if this.record is a model before calling .get() on it. The showPicker method however does not use getValue and assumes this.record is a model with this line:showPicker should call this.getValue on the right instead to prevent hard JS errors when showing a picker with an unmatched valueCode:value[name] = this.record.get(this.getValueField());
Update: Here's my patch that fixes both issues
-
30 Apr 2012 3:57 PM #6
Fixed for the next release. Thanks for the patches.
Sencha Inc.
Robert Dougan - @rdougan
Sencha Touch 2 and Ext JS 4 Core Team Member, SASS/Theming Wizard.
Success! Looks like we've fixed this one. According to our records the fix was applied for
TOUCH-2830
in
Sprint 22 (2.0.2).


Reply With Quote