I am trying to extend the jQuery UI Datepicker to add some validations.
I searched a lot on the Internet, but I could not get any help. I found the SO question jquery-datepicker-function-override , there is no way to change the textinput behavior, the datepicker component only supports the onSelect event, which fires after the date is selected not when we change the date using textinput.
I created a script to show the problem.
I have two date pickers, both showing wrong dates. In this case, the date picker shows the current date of the system. The first text entry contains 05-ddd-2014, and the second contains March 05, 2014, both of which are incorrect dates.
Problem
NOTE.
I know how to use the datepicker component, I want to support checking when I press / enter the keyboard. I need to extend the jQuery UI Datepicker component. The question is not in the date format. To simplify the question, I choose a simple format (dd-M-yy (ie 02-Feb-2014)). The question is how to handle the event of a change in text input in case of incorrect dates.
Currently, I support only one dd-M-yy input format (i.e. February 02, 2014).
When I enter any wrong format directly in the text input (i.e. 02-xxx-2014) , the current date of the system (current behavior) is displayed in the date selection list.
Is there any way I can check the text entered in the text input and assign it a datepicker.
I tried to use the keydown event for textinput, but sometimes it did not give the right key, maybe the jQuery UI Datepicker handles this event.
$('#datepicker').on("keydown", function(e) { var val = this.value; var ar = val.split("-");
Is there any best practice for extending jQuery UI Datepicker or jQuery UI conmponents in general.
javascript jquery jquery-ui datepicker
user3278797 Feb 10 '14 at 10:10 2014-02-10 10:10
source share