I have a modal form that has some date and time fields in it that use flatpickr. I am submitting the form and doing a turbo stream replace. When there are form validation errors it replaces the form and displays the errors, but the flatpickr fields get wiped out back to regular text fields. I’m not sure how to tell the modal or turbo stream to load those fields again on replace.
<%= turbo_stream.replace “new_detail”, partial: “details/form”, locals: { detail: @detail } %>
Any ideas?
Flatpickr is initialized in packs/application.js
document.addEventListener(“turbo:load”, function() {
flatpickr("[data-behavior=‘flatpickr’]", {
altInput: true,
altFormat: “F j, Y”,
dateFormat: “Y-m-d”,
})
$( ‘.flatpickr1’ ).flatpickr({
enableTime: true,
noCalendar: true,
dateFormat: “H:i”,
time_24hr: true
});
$( ‘.flatpickr2’ ).flatpickr({
enableTime: true,
noCalendar: true,
dateFormat: “H:i”,
time_24hr: true
});
})