Using bootstrap-datepicker.js, very nice plugin. Everything works as expected, minus this one case, which could be me missing something within the documentation. Whenever a user enters a date and the textbox looses focus (user goes on to complete the rest of the form), if the user goes back to the textbox and attempts to remove the date, today's date is automatically populated. If you remove today's date, it automatically populates again...repeatedly. Is there an option I have missed that would rectify this situation? If the field was required, it wouldn't be a big deal, however the user has the option of submitting the form without a date. Code below:
$('#start_date').datepicker({
orientation: "bottom auto",
autoclose: true,
todayHighlight: true,
useCurrent: false
}).mask("99/99/9999");
$('#end_date').datepicker({
orientation: "bottom auto",
autoclose: true,
todayHighlight: true,
useCurrent: false
}).mask("99/99/9999");
This is a working fiddle demonstrating the issue: https://jsfiddle.net/f8v5vLmt/3/
There must be a problem with the
mask
plugin you are using. It is setting a value in the field thatdatetime picker
is trying to parse, and it is obviously not a date, so it must be defaulting to current date.Try adding
forceParse: false
to the options.You can check the behaviour is whatyou want in the first field here:
https://jsfiddle.net/f8v5vLmt/5/
Ref: https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#forceparse