Javascript – ExtJS DateField confuse format

datedate formatdatetimeextjsjavascript

I use Ext.form.DateField with specified format is 'd-m-Y', like this:

var sellingDate = new Ext.form.DateField({
    fieldLabel : "Selling date",
    width : 180,
    name: 'sellingDate',
    format: 'd-m-Y',
    allowBlank : false
});

I want this component to complete the input value automatically with given format after it lost focus. I mean if I input the text '040212' (February 4th 2012, in my country we use 'dd-mm-YYYY' as standard date format), it must display that text as '04-02-2012'.
But when debugging at event "change" of DateField, I see that the parsed Date object is "Mon Apr 02 2012". I don't know how to make it work as I expect above. Is there any way to get the raw text from date field, not a parsed Date object? Could you please help me on this?
Thank you so much!

Best Answer

That's simple, add the altFormats config option:

altFormats : String Multiple date formats separated by "|" to try when parsing a user input value and it does not match the defined format

//So in your case, it should be 'dmy'
var sellingDate = new Ext.form.DateField({
    fieldLabel : "Selling date",
    width : 180,
    name: 'sellingDate',
    format: 'd-m-Y',
    altFormats: 'dmy',
    allowBlank : false
});