mymth / vanillajs-datepicker

A vanilla JavaScript remake of bootstrap-datepicker for Bulma and other CSS frameworks
MIT License
743 stars 154 forks source link

Default Date With Data-Date Not Working with Multiple Inputs #162

Closed nrwilliams closed 1 year ago

nrwilliams commented 1 year ago

I have the data-date on a couple inputs. Then when i loop over them and initiate the Datepicker, my default date doesn't work, the input is just blank. Without querySelectorAll it seems to work. You can select and set dates just fine, but on initial load, the defaults i have don't seem to set.

Inputs look like this:

<input data-date="09/3/2023" class="datepickervan">

const elem = document.querySelectorAll(.datepickervan);

        elem.forEach(datefield => {
          new Datepicker(datefield, {
            autohide: true,
            daysOfWeekDisabled: [0, 6],
            todayButton: true
          });
        });
mymth commented 1 year ago

That initial date is ignored because Sep 3, 2023 is Sunday, which is disabled by daysOfWeekDisabled. You should be able to see data-date functioning if you change the initial date to any weekday or remove the daysOfWeekDisabled option.

nrwilliams commented 1 year ago

@mymth That is brilliant haha didn't even think about that. Thanks that worked like a charm!