uxsolutions / bootstrap-datepicker

A datepicker for twitter bootstrap (@twbs)
Apache License 2.0
12.66k stars 6.07k forks source link

Big problems with javascript setting date #2166

Open lmaraneli opened 7 years ago

lmaraneli commented 7 years ago

Expected behaviour

should set value via javascript

Actual behaviour

nothing

Datepicker version used

ex. 1.6.4

Example code

date = moment() $("#DueDate").val(date.format("DD.MM.YYYY")).datepicker('update', { language: 'ka', rtl: false, autoclose: true, format: 'dd.mm.yyyy', todayHighlight: true, date: date.format("DD.MM.YYYY") });

LeonidasJP commented 7 years ago

Try passing only the date to set the datepicker to as second argument to .datepicker. Eg, use: $("#DueDate").val(date.format("DD.MM.YYYY")).datepicker('update', date.format("DD.MM.YYYY"));

You could even omit the date from .datepicker('update'); in that case the Datepicker will be updated to the value of #DueDate.

As explained at http://bootstrap-datepicker.readthedocs.io/en/latest/methods.html#update:

update Arguments:

date (String|Date|Array, optional) date (String|Date, optional) ... Update the datepicker with given arguments or the current input value. The arguments can be either an array of strings, an array of Date objects, multiples strings or multiples Date objects. If date arguments are provided and they are Date objects, it is assumed to be “local” Date objects, and will be converted to UTC for internal use.