ab-datepicker icon indicating copy to clipboard operation
ab-datepicker copied to clipboard

User is free to enter any thing in datepicker text box.

Open rakeshy3 opened this issue 5 years ago • 1 comments

User is free to enter any thing in datepicker text box. it should only allow to enter date in chosen format and date only not any text. Please suggest how I can achieve this.

rakeshy3 avatar Jun 05 '19 15:06 rakeshy3

I've seen that as well (on MOST of the date pickers that use a text field.) I added my own handler to trap that:

$('#date').keydown(function(e) {
	const validKeys = /[0-9\.\-\/]/;
	 if((e.key.match(validKeys))) {
		return true;
	 }
	 else {
	 	return false;
	 }
})

This allows only numbers and "-" or "/" or "." as separators (so you can enter dates as "01/01/2001" or "01-02-2002" or "01.03.2003") It doesn't trap for all possible errors (like entering "/1.2-3") but that can be done as well. I just validate (using moment) on blur of the field.

Now granted that type of input validation could (and really should) be done as part of the module. I just don't have the time to make a PR for it at the moment.

Hope that helps

barlowm avatar Jun 27 '19 20:06 barlowm