Success! Looks like we've fixed this one. According to our records the fix was applied for
TOUCH-1187
in
a recent build.
-
Sencha User
Ext.Date.format should handle nulls
REQUIRED INFORMATION
Ext version tested:
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:
See this URL for live test case: http://
Debugging already done:
Possible fix:
Additional CSS used:
- only default ext-all.css
- custom css (include details)
Operating System:
-
I recently fixed an issue in that method, I'll check to see if it helps this as well.
-
Sencha User
Thanks for update, Jamie, when is it estimated to go out, please?
-
-
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 User
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.
-
Sencha User
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);
}
});