This is a migrated thread and some comments may be shown as answers.

Defaulting current year if user types in month and day?

3 Answers 10 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
Brian Roth
Top achievements
Rank 1
Brian Roth asked on 02 Apr 2014, 03:10 PM
I was trying to figure out a way to update the date input on the DatePicker if a user types in only the month and year.  Most of our users are used to our old Telerik ASP.NET site where this was the default behavior of the date picker control.  Ideally, I'd like to take their input and automatically reformat it to add the year.  But I'm not sure how to achieve this with the Kendo MVC controls.  The change event will not fire for me because the input is considered invalid.  I attempted to add ParseFormats for "MM/dd" to my editor template but in stepping through the kendo source code it seems that this information is not passed through to the javascript object (which may be another issue.)  Is there a good way to achieve this functionality?  Thanks for your help.

Here is what my editor template looks like:
@model System.DateTime?
@(Html.Kendo().DatePickerFor(m => m).ParseFormats(new string[] { "MM/dd" }) )   

Regards,
Brian

3 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 03 Apr 2014, 12:25 PM
Hello Brian,

Setting the parseOptions option through the ParseOption method should be sufficient to accomplish your goal. I prepared a Kendo Dojo demo (there should be no difference between widget defined in this demo and the one defined with a server wrapper) and everything works as expected. Check it and let me know if I am missing something.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Brian Roth
Top achievements
Rank 1
answered on 14 Apr 2014, 07:37 PM
Thanks!  I had a stupid syntax error on my editor that was causing it not to work.  It's working as you described now.  I do have a question about how to best handle this with different cultures.  Most of our users are in the US, so the MM/dd format is preferred for them.  But we do have a some clients in other countries where dd/MM is their expected format.  Is there a good way to make the ParseOptions culture-aware?  Or is there another good way to handle this?

As always, thanks for your help!

Regards,
Brian
0
Georgi Krustev
Telerik team
answered on 15 Apr 2014, 10:39 AM
Hello again Brian,

In general, you can persist the parse formats you would like to support in a specific place, for instance kendo.culture scripts. Thus when you change the internationalization configuration based on the user and/or site setting you can retrieve the correct list of parse formats and set them to the widget.

Regards,
Georgi Krustev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Date/Time Pickers
Asked by
Brian Roth
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Brian Roth
Top achievements
Rank 1
Share this question
or