Last active
August 11, 2022 19:02
-
-
Save TWithers/72c7ee4d80d5b6d63ce25f56a3bab4ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
document.addEventListener('alpine:init', () => { | |
Alpine.data('flatpickr', () => ({ | |
selectedDate: '', | |
init() { | |
const fp = new window.flatpickr(this.$refs.picker, {}); | |
if (typeof window.flatpickrInputs === 'undefined') { | |
window.flatpickrInputs = []; | |
} | |
window.flatpickrInputs.push(fp); | |
fp.config.onChange.push((a, dateStr) => { | |
this.selectedDate = dateStr; | |
}); | |
} | |
}); | |
}); | |
</script> | |
<div x-data="flatpickr"> | |
<input type="text" x-model="selectedDate" x-ref="flatpickrInput"> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment