Defaulting current year if user types in month and day?

4 posts, 0 answers
  1. Brian Roth
    Brian Roth avatar
    136 posts
    Member since:
    Oct 2005

    Posted 02 Apr 2014 Link to this post

    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
  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 03 Apr 2014 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Brian Roth
    Brian Roth avatar
    136 posts
    Member since:
    Oct 2005

    Posted 14 Apr 2014 Link to this post

    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
  5. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 15 Apr 2014 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready