-
6 Dec 2011 8:44 AM #1
Ext.Date.format should handle nulls
Ext.Date.format should handle nulls
REQUIRED INFORMATION
Ext version tested:- Touch 2.0-pr2
- Chrome
- IE8
- FF3 (firebug 1.3.0.10 installed)
- Safari 4
- ____
- 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.
- Create a form containing date picker field
- set the field value to new Date()
- clear the field value on setValue(null) and don't throw exception
- TypeError exception in Ext.date.format
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
Debugging already done:- none
- not provided
- only default ext-all.css
- custom css (include details)
- ________
- WinXP Pro
-
6 Dec 2011 10:23 AM #2Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,653
- Vote Rating
- 14
I recently fixed an issue in that method, I'll check to see if it helps this as well.
-
6 Dec 2011 3:15 PM #3
Thanks for update, Jamie, when is it estimated to go out, please?
-
7 Dec 2011 8:45 AM #4Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,653
- Vote Rating
- 14
PR3 will be very soon.
-
7 Dec 2011 10:18 AM #5Sencha - Sencha Touch Dev Team
- Join Date
- Mar 2007
- Location
- Redwood City, California
- Posts
- 3,653
- Vote Rating
- 14
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; } });
-
15 Dec 2011 7:49 AM #6
DatePicker is OK, Select is not
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.
-
15 Dec 2011 8:13 AM #7
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);
}
});
Success! Looks like we've fixed this one. According to our records the fix was applied for
TOUCH-1187
in
2.0.


Reply With Quote