Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit 97d22b6

Browse files
committed
update docs to describe handling manual date entry with disallowed dates
1 parent 875f78c commit 97d22b6

File tree

3 files changed

+57
-16
lines changed

3 files changed

+57
-16
lines changed

README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -603,16 +603,25 @@ Please note that you must provide the entirety of the localization properties in
603603

604604
Duet Date Picker allows you to disable the selection of specific days. Below is an example of a date picker that is disabling weekends.
605605

606+
Be aware, this only disables selection of dates in the popup calendar. You must still handle the case where a user manually enters a disallowed date into the input.
607+
606608
```html
607609
<label for="date">Choose a date</label>
608610
<duet-date-picker identifier="date"></duet-date-picker>
609611

610612
<script>
611-
const pickerDisableWeekend = document.querySelector("duet-date-picker")
612-
613-
pickerDisableWeekend.isDateDisabled = function isWeekend(date) {
613+
function isWeekend(date) {
614614
return date.getDay() === 0 || date.getDay() === 6
615615
}
616+
617+
const pickerDisableWeekend = document.querySelector("duet-date-picker")
618+
pickerDisableWeekend.isDateDisabled = isWeekend
619+
620+
pickerDisableWeekend.addEventListener("duetChange", function(e) {
621+
if (isWeekend(e.detail.valueAsDate)) {
622+
alert("Please select a weekday")
623+
}
624+
})
616625
</script>
617626
```
618627

docs/index.html

+21-7
Original file line numberDiff line numberDiff line change
@@ -534,22 +534,36 @@ <h2>Required atrribute</h2>
534534
<label for="dateDisabledWeekend">Choose a date</label>
535535
<duet-date-picker class="picker-disabled-weekend" identifier="dateDisabledWeekend"></duet-date-picker>
536536
<script>
537-
const pickerDisableWeekend = document.querySelector(".picker-disabled-weekend")
538-
539-
pickerDisableWeekend.isDateDisabled = function isWeekend(date) {
537+
function isWeekend(date) {
540538
return date.getDay() === 0 || date.getDay() === 6
541539
}
540+
541+
const pickerDisableWeekend = document.querySelector(".picker-disabled-weekend")
542+
pickerDisableWeekend.isDateDisabled = isWeekend
543+
544+
pickerDisableWeekend.addEventListener("duetChange", function(e) {
545+
if (isWeekend(e.detail.valueAsDate)) {
546+
alert("Please select a weekday")
547+
}
548+
})
542549
</script>
543550
<pre><code class="html">&lt;label for="date"&gt;Choose a date&lt;/label&gt;
544551
&lt;duet-date-picker identifier="date"&gt;&lt;/duet-date-picker&gt;
545552
546553
&lt;script&gt;
547-
const pickerDisableWeekend = document.querySelector(".picker-disabled-weekend")
548-
549-
pickerDisableWeekend.isDateDisabled = function isWeekend(date) {
554+
function isWeekend(date) {
550555
return date.getDay() === 0 || date.getDay() === 6
551556
}
552-
&lt;/script&gt;</code></pre> -->
557+
558+
const pickerDisableWeekend = document.querySelector(".picker-disabled-weekend")
559+
pickerDisableWeekend.isDateDisabled = isWeekend
560+
561+
pickerDisableWeekend.addEventListener("duetChange", function(e) {
562+
if (isWeekend(e.detail.valueAsDate)) {
563+
alert("Please select a weekday")
564+
}
565+
})
566+
&lt;/script&gt;</code></pre>-->
553567
<br />
554568
<p>
555569
© 2020 LocalTapiola Services Ltd /

src/index.html

+24-6
Original file line numberDiff line numberDiff line change
@@ -520,24 +520,42 @@ <h2>Required atrribute</h2>
520520
&lt;/script&gt;</code></pre>
521521

522522
<h2>Disable selectable days</h2>
523+
<p>
524+
This only disables selection of dates in the popup calendar. You must still handle the case where a user enters
525+
a disallowed date into the input.
526+
</p>
523527
<label for="dateDisabledWeekend">Choose a date</label>
524528
<duet-date-picker class="picker-disabled-weekend" identifier="dateDisabledWeekend"></duet-date-picker>
525529
<script>
526-
const pickerDisableWeekend = document.querySelector(".picker-disabled-weekend")
527-
528-
pickerDisableWeekend.isDateDisabled = function isWeekend(date) {
530+
function isWeekend(date) {
529531
return date.getDay() === 0 || date.getDay() === 6
530532
}
533+
534+
const pickerDisableWeekend = document.querySelector(".picker-disabled-weekend")
535+
pickerDisableWeekend.isDateDisabled = isWeekend
536+
537+
pickerDisableWeekend.addEventListener("duetChange", function(e) {
538+
if (isWeekend(e.detail.valueAsDate)) {
539+
alert("Please select a weekday")
540+
}
541+
})
531542
</script>
532543
<pre><code class="html">&lt;label for="date"&gt;Choose a date&lt;/label&gt;
533544
&lt;duet-date-picker identifier="date"&gt;&lt;/duet-date-picker&gt;
534545

535546
&lt;script&gt;
536-
const pickerDisableWeekend = document.querySelector(".picker-disabled-weekend")
537-
538-
pickerDisableWeekend.isDateDisabled = function isWeekend(date) {
547+
function isWeekend(date) {
539548
return date.getDay() === 0 || date.getDay() === 6
540549
}
550+
551+
const pickerDisableWeekend = document.querySelector(".picker-disabled-weekend")
552+
pickerDisableWeekend.isDateDisabled = isWeekend
553+
554+
pickerDisableWeekend.addEventListener("duetChange", function(e) {
555+
if (isWeekend(e.detail.valueAsDate)) {
556+
alert("Please select a weekday")
557+
}
558+
})
541559
&lt;/script&gt;</code></pre>
542560
<br />
543561
<p>

0 commit comments

Comments
 (0)