Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

332
Views
How to use flatpickr.js to create a range inputs?

I am trying to use the flatpickr plugin to create a range like pickers accross two different inputs. One input would be for the From and the other one for To.

I tried the following but the minDate and maxDate are not getting set as expected

document.addEventListener('DOMContentLoaded', function () {

    let dateTimeFrom = document.getElementById('From');
    let dateTimeTo = document.getElementById('To');


    let dateTimeFromPicker = flatpickr(dateTimeFrom, {
        enableTime: true,
        dateFormat: 'n/j/Y h:i K',
        onChange: function (selectedDates, dateStr, instance) {
            dateTimeTo.set('minDate', selectedDates[0]);
        }
    });

    let dateTimeToPicker = flatpickr(dateTimeTo, {
        enableTime: true,
        dateFormat: 'n/j/Y h:i K',
        onChange: function (selectedDates, dateStr, instance) {
            dateTimeFrom.set('maxDate', selectedDates[0]);
        }
    });
});

How can I correctly set the range across two inputs?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I was able to get it to work using the following snippet

document.addEventListener('DOMContentLoaded', function () {
        let dateTimeFrom = document.getElementById('From');
        let dateTimeTo = document.getElementById('To');
        let dateTimeToPicker = null;
        let dateTimeFromPicker = flatpickr(dateTimeFrom, {
            enableTime: true,
            dateFormat: 'n/j/Y h:i K',
            onChange: function (selectedDates, dateStr, instance) {
                dateTimeToPicker.set('minDate', selectedDates[0]);
            }
        });

        dateTimeToPicker = flatpickr(dateTimeTo, {
            enableTime: true,
            dateFormat: 'n/j/Y h:i K',
            onChange: function (selectedDates, dateStr, instance) {
                dateTimeFromPicker.set('maxDate', selectedDates[0]);
            }
        });
   
});
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!