Results 1 to 7 of 7

Thread: Ext.Date.format should handle nulls

    Success! Looks like we've fixed this one. According to our records the fix was applied for TOUCH-1187 in a recent build.
  1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    6
    Vote Rating
    0
      0  

    Default Ext.Date.format should handle nulls

    REQUIRED INFORMATION


    Ext version tested:
    • Touch 2.0-pr2

    Browser versions tested against:
    • Chrome
    • IE8
    • FF3 (firebug 1.3.0.10 installed)
    • Safari 4

    DOCTYPE tested against:
    • ____

    Description:
    • Ext.Date.format (null, Ext.util.Format.defaultDateFormat) throws an exception when the first arg is null. As the result it's impossible to clear a value from Ext.field.DatePicker, once it's set to non-null value.

    Steps to reproduce the problem:
    • Create a form containing date picker field
    • set the field value to new Date()

    The result that was expected:
    • clear the field value on setValue(null) and don't throw exception

    The result that occurs instead:
    • TypeError exception in Ext.date.format

    Test Case:

    Code:
    var form = Ext.create('Ext.form.Panel', { items:[{xtype:'datepickerfield'}]});
    var dateField = form.down('datepickerfield');
    dateField.setValue(new Date());
    dateField.setValue(null); // exception thrown here


    HELPFUL INFORMATION


    Screenshot or Video:
    • attached

    See this URL for live test case: http://


    Debugging already done:
    • none

    Possible fix:
    • not provided

    Additional CSS used:
    • only default ext-all.css
    • custom css (include details)

    Operating System:
    • ________
    • WinXP Pro

  2. #2
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    19
      0  

    Default

    I recently fixed an issue in that method, I'll check to see if it helps this as well.

    Sencha Inc

    Jamie Avins

    @jamieavins

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    6
    Vote Rating
    0
      0  

    Default

    Thanks for update, Jamie, when is it estimated to go out, please?

  4. #4
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    19
      0  

    Default

    PR3 will be very soon.

    Sencha Inc

    Jamie Avins

    @jamieavins

  5. #5
    Sencha User Jamie Avins's Avatar
    Join Date
    Mar 2007
    Location
    Redwood City, California
    Posts
    3,661
    Vote Rating
    19
      0  

    Default

    Turned out to be unrelated, but the fix is rather simple. Here's an override to hold you over:

    Code:
    Ext.override(Ext.field.DatePicker, {
        updateValue: function(newValue) {
            var picker = this.getPicker();
            if (this.initialized && picker) {
                picker.setValue(newValue);
            }
    
            // Ext.Date.format expects a Date
            if (newValue !== null) {
                this.getComponent().setValue(Ext.Date.format(newValue, Ext.util.Format.defaultDateFormat));
            }
    
            this._value = newValue;
        }
    });

    Sencha Inc

    Jamie Avins

    @jamieavins

  6. #6
    Sencha User
    Join Date
    Oct 2011
    Posts
    6
    Vote Rating
    0
      0  

    Default DatePicker is OK, Select is not

    Thanks Jamie
    PR3 fixed the date issue. A pretty similar problem is found on Ext.field.Select

    var field = new Ext.field.Select({
    option: [{text:'empty', value:''}, {text:'A', value: 'a'}]
    });
    field.setValue('a'); // OK, selects A
    field.setValue(''); // misses to select 'empty', leaving the previous choice of A unchanged

    The problem starts in Select.js, line #142
    index = this.getStore().find(this.getValueField(), value);

    where index receives -1 when value is an empty string ''.
    Underlying Store tries to construct filter function to find the value and fails to do so evaluating Ext.isEmpty(value) as true. Correct is to treat value='' as valid string and discriminate value=null or undefined.

  7. #7
    Sencha User
    Join Date
    Oct 2011
    Posts
    6
    Vote Rating
    0
      0  

    Default

    Ext.define('Ext.field.SelectFix', {
    override: 'Ext.field.Select',
    applyValue: function(value) {
    if (value == '') {
    console.log('select empty value');
    var store = this.getStore(),
    field = this.getValueField();
    index = store.findBy(function(item) {
    return item.get(field) == value;
    });
    if (index == -1) {
    field = this.getDisplayField();
    index = store.findBy(function(item) {
    return item.get(field) == value;
    });
    }
    return store.getAt(index);
    }
    return this.callParent(arguments);
    }
    });

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •