-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flatpickr change minDate maxDate on the fly #1380
Comments
Hello You should store the instance of Flatpickr somewhere and then use the Here is an example I used some time ago, It was in the Stimulus framework, but I think you can easily extract the logic out of it. import { Controller } from "stimulus";
import flatpickr from "flatpickr";
import "flatpickr/dist/flatpickr.css";
export default class extends Controller {
static targets = ["start", "end"];
connect() {
this.startPicker = flatpickr(this.startTarget, {
onClose: this.closeStart.bind(this)
});
this.endPicker = flatpickr(this.endTarget, {
onClose: this.closeEnd.bind(this)
});
}
closeStart(selectedDates, dateStr, instance) {
this.endPicker.set("minDate", dateStr);
}
closeEnd(selectedDates, dateStr, instance) {
this.startPicker.set("maxDate", dateStr);
}
} |
Thanks I solved in this way let startpicker = flatpickr('#start_time', {
locale: 'it',
enableTime: true,
plugins: [
new confirmDate({
confirmIcon: "<i class='fa fa-check'></i>",
confirmText: '',
showAlways: true,
}),
],
showAlways: false,
theme: 'airbnb',
time_24hr: true,
altInput: true,
altFormat: 'F j, Y H:i',
dateFormat: 'Z',
weekNumbers: true,
maxDate: $('#end_time').attr('value'),
onClose: function(selectedDates, dateStr, instance) {
endpicker.set('minDate', dateStr);
},
});
let endpicker = flatpickr('#end_time', {
locale: 'it',
enableTime: true,
plugins: [
new confirmDate({
confirmIcon: "<i class='fa fa-check'></i>",
confirmText: '',
showAlways: true,
}),
],
showAlways: false,
theme: 'airbnb',
time_24hr: true,
altInput: true,
altFormat: 'F j, Y H:i',
dateFormat: 'Z',
weekNumbers: true,
minDate: $('#start_time').attr('value'),
onClose: function(selectedDates, dateStr, instance) {
startpicker.set('maxDate', dateStr);
},
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi I'm trying to replace the datetimepicker with flatpickr but I can't handle this situation. Not wishing to use the Range plugin of flatpickr I would like to be able to change the minDate or maxDate of an instance using the onChange event. Unfortunately I found little information about this passage on the guides
I tried to play with
$('#start_time')[0]._flatpickr.config._maxDate = Date()
it's work but there is no auto refresh of the elementThanks ;)
The text was updated successfully, but these errors were encountered: