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

127
Views
Clearing value of bootstrap datepicker with viewmode years or months

When I open a bootstrap modal I get the data of previous months or years I tried to filter some data with, with this data some months or years are already selected in my datepicker. When I want to add some more months or years to the datepicker it adds the selected months or years in the textfield of the datepicker.

This also happens when I select the previously selected month or year, I would like to prevent this from happening, so I set the immediateUpdates option to true when I initialize the datepicker. This fixed my problem mentioned above, but now a new problem arises.

When I open the datepicker and select a month or year it now clears my previous values but I'm unable to select new months or years in the selectpicker when I click on them. They are only selectable through the arrow keys and enter key on my keyboard, this won't do and I'm kinda runnning out of ideas on how to fix this.

Beneath this is my HTML and JS code I use to create the datepicker.

HTML:

<input type="text" class="form-control" name="selected_years[]" placeholder="select years" id="years_datepicker" autocomplete="off"/> 
<input type="text" class="form-control" name="selected_months[]" placeholder="select months" id="month_datepicker" autocomplete="off"/>

JS:

function initDatePicker(datePicker, format) {
    let DatePicker = $(datePicker);

    let datepickerFormat = "";
    let datepickerView = "";

    if (format === "yearPicker") {
        datepickerFormat = "yyyy";
        datepickerView = "years";
    } else if (format === "monthPicker") {
        datepickerFormat = "mm-yyyy";
        datepickerView = "months";
    }

    DatePicker.datepicker({
        language: local_language,
        format: datepickerFormat,
        startView: datepickerView,
        minViewMode: datepickerView,
        maxViewMode: datepickerView,
        multidate: true,
        multidateSeparator: ", ",
        todayHighlight: true,
        startDate: start_of_reports,
        endDate: end_of_reports,
        disableTouchKeyboard: true,
        immediateUpdates: true
    });
}
about 4 years ago · Juan Pablo Isaza
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!