Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-2830 in a recent build.
  1. #1
    Sencha User
    Join Date
    Mar 2007
    Posts
    411
    Vote Rating
    17
    jweber will become famous soon enough

      0  

    Default 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

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,824
    Vote Rating
    836
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    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
    ________________
    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 in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Nov 2011
    Posts
    61
    Vote Rating
    3
    FrankK is on a distinguished road

      0  

    Default


    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;
        }
    });

  4. #4
    Touch Premium Member
    Join Date
    Jul 2011
    Posts
    25
    Vote Rating
    0
    tareed is on a distinguished road

      0  

    Default 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 !

  5. #5
    Sencha Premium Member
    Join Date
    Apr 2008
    Posts
    246
    Vote Rating
    23
    themightychris will become famous soon enough themightychris will become famous soon enough

      0  

    Default


    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:
    Code:
    value[name] = this.record.get(this.getValueField());
    showPicker should call this.getValue on the right instead to prevent hard JS errors when showing a picker with an unmatched value

    Update: Here's my patch that fixes both issues
    Chief Architect @ Jarv.us Innovations
    Co-captain @ Code for Philly
    Co-founder @ Devnuts - Philadelphia Hackerspace

  6. #6
    Sencha - Sencha Touch Dev Team rdougan's Avatar
    Join Date
    Oct 2008
    Posts
    1,158
    Vote Rating
    6
    rdougan will become famous soon enough

      0  

    Default


    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.