Datepicker Disable Day From Array Question
Hi there,
I am trying to disable certain days based on a user's selection in another form. I understand you need to use beforeShowDay and for example date.getDay() !== [0]
But how do I achieve this when more than one day can be selected from checkboxes? I have passed the values to an array, but seem to be having trouble disaplying this array in the beforeShowDay function:
HTML
- <form>
- <div class="field">
- <input class="input" id="disableDate" value="Date to disable">
- </div>
- <div id="disableDays">
- <label class="label">Select Which Days to Exclude</label>
- <div class="field">
- <input type="checkbox" id="Sunday" class="is-checkradio" name="Sunday" data-value="0">
- <label for="Sunday" class="label">Sunday</label>
- </div>
- <div class="field">
- <input type="checkbox" id="Monday" class="is-checkradio" name="Monday" data-value="1">
- <label for="Monday" class="label">Monday</label>
- </div>
- <div class="field">
- <input type="checkbox" id="Tuesday" class="is-checkradio" name="Tuesdayy" data-value="2">
- <label for="Tuesday" class="label">Tuesday</label>
- </div>
- <div class="field">
- <input type="checkbox" id="Wedndesday" class="is-checkradio" name="Wedndesday" data-value="3">
- <label for="Wedndesday" class="label">Wedndesday</label>
- </div>
- <div class="field">
- <input type="checkbox" id="Thursday" class="is-checkradio" name="Thursday" data-value="4">
- <label for="Thursday" class="label">Thursday</label>
- </div>
- <div class="field">
- <input type="checkbox" id="Friday" class="is-checkradio" name="Friday" data-value="5">
- <label for="Friday" class="label">Friday</label>
- </div>
- <div class="field">
- <input type="checkbox" id="Saturday" class="is-checkradio" name="Saturday" data-value="6">
- <label for="Saturday" class="label">Saturday</label>
- </div>
- <div class="field">
- <input type="submit" class="button is-medium is-primary" value="Save">
- </div>
- </div>
- </form>
- <div id="customerCalendar"></div>
- jQuery(function($) {
- let disabledDays = [];
- $("form").submit(function(e) {
- dayValue = $('#disableDays input:checked').map(function() {
- return $(this).data('value')
- }).get();
- disabledDays.push(dayValue)
- return false
- });
- $("#customerCalendar").datetimepicker({
- beforeShowDay: function(date) {
- let getDay
- for (d = 0; d < disabledDays; d++) {
- getDay = date.getDay() !== [disabledDays]
- return getDay
- }
- return [getDay]
- },
- timeFormat: 'HH',
- minDate: +1
- });
-
});