DatePicker date is not updated when value of underlying input field has been set programically

1,153 views
Skip to first unread message

Ondřej Kaláb

unread,
Sep 13, 2017, 8:48:52 AM9/13/17
to bootstrap-datepicker
Hi,

I am updating value of the underlying input field in some back events (form reset to default values), but the selected date in DatePicker when opened remains the previous one before input value reset.

Yes, I can make the DatePicker to update explicitly by $('#my-datepicker').datepicker('update'), but - is there a reason why DatePicker does not update itself on value change? 

Thanks.

Ondra

Ondřej Kaláb

unread,
Sep 14, 2017, 4:57:21 AM9/14/17
to bootstrap-datepicker
I already know, it's standard in DOM that the change event is invoked bz user.
So I use - reluctantly - this workaround:

// Workaround:
// DatePicker doesn't know about programmic change of input's value.
// - jQuery docs (http://api.jquery.com/change/): "Note: Changing the value of an input element using JavaScript, using .val() for example, won't fire the event."
// - DOM Level 2 Event Specification (https://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html): "The change event occurs when a control loses the input focus and its value has been modified since gaining focus."
Meteor.defer(function() {
$('#my-datepicker').datepicker('update');
});
Reply all
Reply to author
Forward
0 new messages