PDA

View Full Version : DatePicker problem when 'day' slot doesn't exist.



colworx
3 Aug 2011, 1:45 PM
Hi, I'm using the latest svn version of Sencha Touch.

I'm using a DatePicker for a credit card expiration date field, so I have it configured to not show the 'day' slot:

slotOrder: ['month', 'year']
When moving the month field, onSlotPick() attempts to update the daySlot store to reflect the new month. The causes JavaScript errors if the day slot doesn't exist.

My fix for now is below. I just added an if statement.


onSlotPick: function(slot, value) {
var name = slot.name,
date, daysInMonth, daySlot;

if (name === "month" || name === "year") {
daySlot = this.child('[name=day]');
if (daySlot) { // <--- my fix
date = this.getValue();
daysInMonth = this.getDaysInMonth(date.getMonth()+1, date.getFullYear());
daySlot.store.clearFilter();
daySlot.store.filter({
fn: function(r) {
return r.get('extra') === true || r.get('value') <= daysInMonth;
}
});
daySlot.scroller.updateBoundary(true);
}
}


Ext.DatePicker.superclass.onSlotPick.apply(this, arguments);
},

colworx
3 Aug 2011, 1:54 PM
Also there are more problems I've just run into with setting the date when the day slot doesn't exist. Hopefully I can work around them.

Perhaps this thread belongs in "Feature Requests" instead of bugs. I didn't realize this functionality isn't supported.

colworx
3 Aug 2011, 2:22 PM
Well here's my temp fix for getValue()...


getValue: function() {
var value = Ext.DatePicker.superclass.getValue.call(this),
daysInMonth = this.getDaysInMonth(value.month, value.year),
day = Math.min(value.day, daysInMonth);

day = (day)? day : 1;

return new Date(value.year, value.month-1, day);
},


Also, in my application to change the date format this was necessary:


Ext.apply(Ext.util.Format, {
defaultDateFormat: 'm/Y'
});