javascriptdatepickerpickadate

Datepicker pickadate prefill multiple picker


I have multiple datepickers to choose a range and send it with the form. For this is use following library Date picker. Now i want to prefill the datepicker with given values.

My html:

<input type="text" class="datepicker" id="select-date-from" name="date-from" autocomplete="off">
<input type="text" class="datepicker" id="select-date-until" name="date-until" autocomplete="off">

JS:

$('.meetings-datepicker').pickadate({options});

I already found:

var $input = $('.datepicker').pickadate()

// Use the picker object directly.
var picker = $input.pickadate('picker')

It works if I replace the class with an id but then i would have to initialize each datepicker seperate. So how can you fill out multiple pickers if they are initialized through a class?

I already tried sth like this:

var picker = $input[0].pickadate('picker');
picker.set('select', new Date('{{ request('date-from') }}'));

but it throws an error:

TypeError: $input[0].pickadate is not a function

I also tried

$('#select-date-from').pickadate('set', 'select', (new Date('{{ request('date-from') }}')));

Solution

  • These have to be initialized individually by each field

    $('#select-date-from').pickadate({options});
    
    $('#select-date-until').pickadate({options});