Hello Metronic Support Team,
I'm having issues with the KTDatepicker component not initializing properly. I've tried multiple approaches but none seem to work. Here's what I've discovered:
Environment:
window.KTDatepicker (with lowercase 'p')The Problem:
The date picker doesn't initialize automatically when elements have data-kt-date-picker="true" attribute, and I cannot access instances programmatically.
What I've Tried:
Automatic Initialization:
data-kt-date-picker="true" attribute to input elementsUsing createInstances() and init():
KTDatepicker.createInstances() and KTDatepicker.init()Checking Available Methods:
KTDatepicker has only two static methods: createInstances and initgetInstance() method available (unlike other KT components)Direct Instance Creation:
new KTDatepicker(element) and new KTDatepicker(element, config)Checking Element Properties:
element.ktDatePicker, element.KTDatePicker, element.ktDatepickerCode Example:
<!--begin::Date Range Input-->
<div class="kt-input w-64">
<i class="ki-outline ki-calendar"></i>
<input class="grow"
data-kt-date-picker="true"
data-kt-date-picker-action-buttons="true"
data-kt-date-picker-display-months-count="2"
data-kt-date-picker-input-mode="true"
data-kt-date-picker-months-to-switch="1"
data-kt-date-picker-position-to-input="left"
data-kt-date-picker-selection-dates-mode="multiple-ranged"
data-kt-date-picker-type="multiple"
id="date-range-input"
placeholder="Select date range"
readonly=""
type="text"/>
</div>
<!--end::Date Range Input-->
Scripts Loaded (in order):
Questions:
KTDatepicker.createInstances() automatically initialize all elements with data-kt-date-picker attribute on page load, or do I need to call it manually?getInstance() method)hidden class), do I need special handling?Additional Context:
Any guidance or example code would be greatly appreciated!
Thank you, MATHEUS
The datepicker in Metronic 9 Tailwind does not initialize automatically; you need to create it manually using new KTDatepicker(element, fun games, options) and save the instance for later use.
google --- BBCODE --- [URL=https://google.com]google[/URL] [url=https://google.com]google[/url] --- RARE --- URL=https://google.com/]google[/URL] [url=https://google.com/]google[/url] [link=https://google.com/]google[/link] [link name=google]https://google.com/[/link] ((https://google.com/)) ((https://google.com/ google)) [https://google.com/ google] [[https://google.com/ google]] [L=google]https://google.com/[/L] "google":https://google.com/ google
Hi Matheus
The datepicker is Metronic. KTUI does not provide a datepicker.
KTDatePicker.init() runs on page load via KTComponents.init() (called on DOM ready). If it isn’t working:
Ensure scripts load in this order:
core.bundle.js (or ktui.min.js)
Your layout/demo file that calls KTComponents.init()
Check that the element is visible when initialization runs. Hidden elements (e.g., display: none or hidden) may not initialize correctly.
Thanks