触发flatpickr
事件时,我找不到在onChange
中区分时间选择事件和日历事件的方法。
const instance = flatpickr(flatpickrRef.current, {
mode: 'range',
enableTime: true,
time_24hr: true,
defaultDate: defaultDate as unknown as number,
disable: [
date => {
return date > new Date();
},
],
positionElement: positionElementRef.current,
onClose,
onChange,
});
最佳答案
选择日期或更改时间时会触发mousedown
事件
const instance = flatpickr(".flatpickr", {
mode: 'range',
enableTime: true,
time_24hr: true,
disable: [
date => {
return date > new Date();
},
],
onChange: () => {
console.log(event ? 'Date Changed' : 'Time Changed')
},
});
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></script>
<div class="flatpickr">
<input name="test" value="03.07.2019" type="text" data-input>
<a class="input-button" title="toggle" data-toggle>
<i class="icon-calendar"></i>
</a>
</div>