- Plugins
- Advanced Datepicker
Plugins
Tailwind CSS Datepicker
Datepicker JavaScript plugin.
Installation
To get started, install Vanilla Calendar Pro and Lodash plugin via npm with Preline UI's Datepicker plugin, you may skip Preline UI's plugin installation step if you are already using Preline UI as a package.
npm i vanilla-calendar-pro lodash @preline/datepicker
Data Options
Vanilla Calendar Pro
Please note that this component requires the use of the Vanilla Calendar Pro plugin. Most options available in the plugin are available in our wrapper.
Methods
Vanilla Calendar Pro
Please note that this component requires the use of the Vanilla Calendar Pro plugin. Most methods available in the plugin are available in our wrapper.
The HSDatepicker
object is contained within the global window
object
Get current state.
const form = document.querySelector('#subscription-form');
form.addEventListener('submit', (evt) => {
evt.preventDefault();
const { element } = HSDatepicker.getInstance('#datepicker', true);
const { selectedDates, selectedTime } = element.getCurrentState();
const formData = new FormData(event.target);
const serializedData = Object.fromEntries(formData.entries());
serializedData.selectedDates = selectedDates;
serializedData.selectedTime = selectedTime;
fetch('/submit', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(serializedData)
})
.then((response) => response.json())
.then((data) => {
console.log('Success:', data);
})
.catch((error) => {
console.error('Error:', error);
});
});
Events
When select changes event example.
const { element } = HSDatepicker.getInstance('#datepicker', true);
element.on('change', (data) => {...});
Actions
Vanilla Calendar Pro
Please note that this component requires the use of the Vanilla Calendar Pro plugin. Most actions available in the plugin are available in our wrapper.
When change month arrow was clicked.
const datepicker = new HSDatepicker(document.querySelector('#datepicker'), {
onClickArrow: () => {
alert('Arrow clicked!');
}
});
Demo examples
Looking for prebuilt UI components based on the Tailwind CSS? Preline UI packs hundreds of component examples for all your website needs.