Setting dateFormat of jquery ui datepicker restricts free text in input -
i using jquery ui datepicker. want set dateformat like: "dd/mm/yy", javascript is:
$("#datepicker").datepicker({ dateformat: "dd/mm/yy" });
and relevant html is:
<input type='text' id='datepicker'>
however, doing restricts text can entered input element (i can't enter "-" or "." example).
i need functionality because want users able freely enter date other "date delimiting" options (eg: "5-5-16"). not possible because "-" symbol cannot entered after specifying "dateformat" option.
is there way fix or bug?
you can this,you need specify formats in parsedate method
$.datepicker.inputformats = ["dd-mm-yy", "dd/mm/yy", "dd mm yy"];//list formats accepted here $.datepicker.originalparsedate = $.datepicker.parsedate; $.datepicker.parsedate = function (format, value, settings) { var date; function testparse(format, value, settings) { if ( ! date ) { try { date = $.datepicker.originalparsedate(format, value, settings); } catch (error) { } } } testparse(format, value, settings); for(var n = 0, stop = $.datepicker.inputformats ? $.datepicker.inputformats.length : 0; n < stop; n++){ testparse($.datepicker.inputformats[n], value, settings); }; return date; };
the above code here https://stackoverflow.com/a/18839641/4810628
Comments
Post a Comment