Skip to content

Picker shows wrong month calendar. #48

@imbens

Description

@imbens

Steps to reproduce:

  1. Wait until the 31st of a month (eg. today) whose successor has less than 31 days.
  2. Open the demo link: https://brianblakely.github.io/nodep-date-input-polyfill/
  3. Click on the first field.
  4. Select the next month.
    The month selector will show the next month, but the picker will show a calendar for the month after that.

This is caused by the following code in picker.js:
this.month.addEventListener(change, ()=> { this.date.setMonth(this.month.value); this.refreshDaysMatrix(); });
setMonth will update the month, but the next month has only 30 days. The Date object will now represent the first of the month after the next month.
An easy fix is:
this.month.addEventListener(change, ()=> { this.date.setMonth(this.month.value, 1); this.refreshDaysMatrix(); });
This makes sure that setMonth sets the Date object to the first of the next month. See also https://stackoverflow.com/questions/14680396/the-date-getmonth-method-has-bug
Apparently the problem does not happen in Chrome. It does happen in Safari.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions