Flatpickr is an enhanced input[type="date"] UI control. Lean, UX-driven, and extensible, yet it doesn’t depend on any libraries.

We have overridden their legacy styles to match our form control element style. So, you are ready to get started now.

You have to take note that Flatpicker instance is managed by the DatePicker component. Whereas the DatePicker component is not included as a core component. So you have to import it manually when it is actually needed on the page.


                    

But with that being said, you can also add it as a core component at any time through the main.js file.

Basic Date Picker

Get started with the basic datepicker without any config. Set the data-datepicker attribute to any regular date input element.


                            

Form Control

You should wrap the date input element with form-control in order to use the options of the regular input element, like size options and the input groups.


                            

Basic Time Picker

You can switch the datepicker out with the timepicker by setting more options provided by Flatpickr. Take a look at the example:


                            

Disabled State

Follow this examples to apply the disabled option.


                            

Initializing

You can use one of these two methods to initialize the Tom Select instance.

Via Data Attributes

The easiest way to initialize the Flatpickr instance is by using data attributes. We already gave examples of how to use this method above. If you haven't checked it out yet, just scroll back to the top.

Just set the data-datepicker attribute to the native input element and you are done. If you want to pass flatpickr options, you can add more data-datepicker-{key}="{value}" to it. The value can be a standard string or JSON formatted.

Via Javascript

Initialize the flatpickr instance by calling the DatePicker.createInstance(element, settings) function.


                        
Function Description
DatePicker.createInstance(element, options) Create a Flatpickr instance.
DatePicker.getInstance(element, options) If any, get the Flatpickr instance.
DatePicker.getOrCreateInstance(element, options) Get the Flatpickr instance if there is one. Create it if necessary.
DatePicker.destroyInstance(element) To destroy a Flatpickr instance. Usually called before removing the element.
DatePicker.dataApi(wrapperElement) Execute the Data API within the specified wrapperElement.

API

If you need more than that, please check out their official docs directly. There are more examples that you can try out as well.