Multiple date formats in jQuery UI's datepicker

jQuery UI's datepicker supports one public format and, optionally, one internal one. However, if you're wanting to support multiple public formats, you're out of luck. In my scenario, I wanted to support

Having the top-most rule in effect, entering a date like 20130901 (September 1st, 2013) would make the datepicker change my value to today's date in the specified formatting, which was not what I wanted.

To fix the issue, I set the least-restrictive format (yy-mm-dd) as the dateFormat:




... and added a keydown event listener to the DOM element I attached my datepicker to, so that it would hide the datepicker as the user started to enter input:




With these two modifications in place, my datepicker now supported my two date formats for manual entry, while maintaining its click functionality, formatting any clicked date as configured in dateFormat.

I hope this'll save you some time, if you're ever in the same position. :-)

Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints