1

I can't get bootstrap-datepicker (https://github.com/uxsolutions/bootstrap-datepicker) to initialize the proper way or call any methods or events on it.

I'm using Laravel 5.4.7 / Vue 2.3.3 / jQuery 3.1.0

My html look like this:

<input type="text" data-provide="datepicker" />

But when I try to initialize the datepicker using the "official" way it doesn't set any of the properties (no errors either):

    $('.datepicker').datepicker({
        todayHighlight: true
    });

It doesn't matter where I place the code (beginning, end, vue created-method, vue mounted-method, $nextTick).

However setting the values like this works:

$.fn.datepicker.defaults.todayHighlight = true;

Unfortunately since non of the other methods or events seem to work either just using the $.fn.datepicker.defaults is not enough.

Does anyone have a clue on what might be wrong?

2
  • did you added jQuery library before your datepicker library? Jun 7, 2017 at 10:58
  • 2
    Add class = "datepicker" in your input field Jun 7, 2017 at 11:03

1 Answer 1

2

Change your input field code to this:

<input type="text" data-provider="datepicker" class="datepicker" />

The issue was of CSS selector i.e. you were searching for an element with datepicker class but their was no such element.

So just add the class attribute to it.

3
  • 1
    Thanks! I overlooked this.. the doc is a bit incosistent with it's examples. I assumed the data-provider="datepicker" tag would be enough. Jun 7, 2017 at 11:25
  • 1
    @ArnovanOordt You could use $('[data-provide="datepicker"]') if you want to use that instead of a class name.
    – Roy J
    Jun 7, 2017 at 14:10
  • @RoyJ Yes, but the jQuery code was using the class selector, so adding a class attribute is more easy in this case Jun 7, 2017 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.