PDA

View Full Version : [CLOSED] DateField Customisation



RajivDutt
Dec 12, 2013, 2:53 PM
I am looking to give some more ease to the end user to allow multiple formats of date.

For example i want the date field Accepts typed-in dates in various formats:
1.1.13
01-01-2013
1 Jan 13
1Jan
1 January

Currently the control allows to give format string, but that is only one format i can give (dd/MM/yyyy) or (dd.MM.yyyy).



@(Html.X().DateField().ID("myDate").Format("dd/MM/yyyy"))


Can you suggest me how to customize existing DateField control?

Thanks,
Rajiv Dutt

Daniil
Dec 12, 2013, 3:21 PM
Hi @RajivDutt,

It looks you are looking for a DateField's AltFormats property.
http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Date-cfg-altFormats

RajivDutt
Dec 12, 2013, 5:28 PM
Hi @RajivDutt,

It looks you are looking for a DateField's AltFormats property.
http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.Date-cfg-altFormats

Thanks, it looks like a good choice, but there are some issues, after i use the AltFormat.

As per the default behavior when i type 11/12 and press Tab... it converts it to 11/12/2013. Which is my requirement as well.
But after applying the AltFormat Property, this default behavior goes away.

Sample Code :

@(Html.X().DateField().ID("myDate").Format("dd/MM/yyyy").AltFormats("dd.MM.yyyy"))

Baidaly
Dec 12, 2013, 8:11 PM
Hello!

To do so you need to add another AltFormat value:


@(Html.X().DateField().ID("myDate").Format("dd/MM/yyyy").AltFormats("dd.MM.yyyy|m/d"))

It worked before because by default AltFormat has the following value:


m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|n-j|n/j

RajivDutt
Dec 13, 2013, 3:06 PM
Hello!

To do so you need to add another AltFormat value:


@(Html.X().DateField().ID("myDate").Format("dd/MM/yyyy").AltFormats("dd.MM.yyyy|m/d"))

It worked before because by default AltFormat has the following value:


m/d/Y|n/j/Y|n/j/y|m/j/y|n/d/y|m/j/Y|n/d/Y|m-d-y|m-d-Y|m/d|m-d|md|mdy|mdY|d|Y-m-d|n-j|n/j


Thanks, it works great. Now if i want to implement Jan & January also, what will be the AltFormat?

Baidaly
Dec 13, 2013, 6:08 PM
You can find all formats here: http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.Date

Daniil
Dec 16, 2013, 4:30 AM
Please note that AltFormats should be set up using the .NET data/time format. When it will be converted to the PhP format automatically. Ext.NET and ExtJS operates with the PhP date/time format on client.