-
12 Sep 2011 4:50 AM #1
Format datepickerfield result.
Format datepickerfield result.
Hi guys,
I'd like to know how to format the result of a datepickerfield, to leave the text as mmm dd, yyyy (ie September 12, 2011).
I've tried different approaches found in the web, but without luck.
Here is my current code, and after a date is picked (also at start because I'm setting today as default), the date text field shows in mm/dd/yyyy format.
Tks in advance!Code:{ id: 'id_dateField', xtype: 'datepickerfield', dateformat: 'F j, Y', type: 'date', value: { day: Date.today().getDate(), month: Date.today().getMonth() + 1, year: Date.today().getFullYear() }, picker: { doneButton: 'Search', slotOrder: ['month', 'day', 'year'], useClearIcon: true, hideOnMaskTap: true, }, name : 'date', label: 'Date', inputCls: 'inputRightAligned' }
Regards,
Milton Rodriguez
-
21 Sep 2011 3:10 AM #2
Unanswered Format datepickerfield result.
Unanswered Format datepickerfield result.
Hi guys, any one that can help me on that ?
-
21 Sep 2011 10:01 AM #3
[Solved] Format datepickerfield result
[Solved] Format datepickerfield result
Well, sadly I've not found an answer in the forum, and nobody answer my question, so, doing more researches and mixing between Ext.js, sencha and others resources found in internet, plus some creativity, I've a very simple solution. Just add listeners to the datepickerfield for change and afterrender events (last one for initial date) and set the dom element value with the picker value parsed.
At the end, the form item must looks like the following:
Code:{ xtype: 'datepickerfield', name: 'date', label: 'Date', inputCls: 'inputRightAligned', value: { day: Date.today().getDate(), month: Date.today().getMonth() + 1, year: Date.today().getFullYear() }, picker: { slotOrder: ['month', 'day', 'year'], useClearIcon: true, hideOnMaskTap: true, doneButton: 'Search' }, listeners: { afterrender: function() { this.fieldEl.dom.value = this.getValue().toString("MMMM d, yyyy"); }, change: function() { this.fieldEl.dom.value = this.getValue().toString("MMMM d, yyyy"); } } }
-
28 May 2012 1:05 PM #4
Nice solution. But I am a bit surprised fo find that Sencha does not have a dateformat property?
-
23 Sep 2012 11:44 PM #5
Hi, this is another simple solution to format datepickerfield result as provided here http://docs.sencha.com/touch/2-0/#!/api/Ext.Date
var formValues = form.getValues();
var dt = new Date(formValues.birthday); //birthday is the datepickerfield result
dt = Ext.Date.format(dt,'F d, Y') ;
Have fun coding.


Reply With Quote