jQueryのflatpickrを使ってカレンダーを作成しています。
カレンダーの日付をクリックした際に、その日付が「選択」されたのか「選択取り消し」されたのかを知りたいです。
flatpickrのEventに onChange(selectedDates, dateStr, instance)があったので、その引数である (instance.selectedDateElem)をみて、classListに"selected"があるかどうかで判定をしようと思ったのですが、「選択」「選択取り消し」共に "selected"が付いてしまっているため、判定ができませんでした。
どのようにすれば判定ができるかご存知の方がいましたら教えていただきたいです!
「jQueyr - flatpickr ドキュメント」
英語
日本語
「環境」
Google Chrome バージョン: 69.0.3497.100(Official Build) (64 ビット)
「実際に書いたコード①」
javascript
1const config = { 2 altInput: true, 3 altFormat: "d", 4 locale: "ja", 5 dateFormat: "Y/m/d", 6 mode: "multiple", 7 inline: true, 8 shorthandCurrentMonth: true, 9 altInputClass: "hidden-altInput", 10 minDate: '"' + nextYear + '/' + nextMonth + '"', //翌月のカレンダーだけ表示 11 maxDate: '"' + nextYear + '/' + nextMonth + '/' + nextDay + '"', 12 onChange: function (selectedDates, dateStr, instance) { 13 console.log(instance.selectedDateElem.classList); 14 } ...
「実際に書いたコード②」
javascript
1const config = { 2 altInput: true, 3 altFormat: "d", 4 locale: "ja", 5 dateFormat: "Y/m/d", 6 mode: "multiple", 7 inline: true, 8 shorthandCurrentMonth: true, 9 altInputClass: "hidden-altInput", 10 minDate: '"' + nextYear + '/' + nextMonth + '"', //翌月のカレンダーだけ表示 11 maxDate: '"' + nextYear + '/' + nextMonth + '/' + nextDay + '"', 12 onChange: function (selectedDates, dateStr, instance) { 13 console.log(this.selectedDateElem.classList); 14 } ...