Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MaterializeCSS datepicker: setDate does not update the view

Using MaterializeCSS 1 rc2, I try to update the date of my DatePicker from Javascript.

My HTML

<form action="#" novalidate>
   <input type="text" class="datepicker" name="date" id="datepicker">
</form>

My JS

function changeDate(date) {
    /* date is a javascript Date object */
    var datepicker = document.getElementById('datepicker');
    var instance = M.Datepicker.getInstance(datepicker);
    instance.setDate(date);
}

Looking at the console, all the variables are set to their expected value. When I click on the DatePicker, that's also the expected date which is displayed (the one I use in changeDate). But the text in the input field does not change...

like image 611
ValLeNain Avatar asked Aug 15 '18 16:08

ValLeNain


1 Answers

My friend, you have found a bug in MaterializeCSS!

I can suggest you my workaround: call instance._finishSelection() after calling instance.setDate() to see your changes.

  • https://github.com/Dogfalo/materialize/issues/6074
like image 147
Valerio Bozz Avatar answered Oct 25 '22 19:10

Valerio Bozz