-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Initialize year selection to current year #372
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
base: main
Are you sure you want to change the base?
Conversation
to-do-notifications/scripts/todo.js
Outdated
| year.value = 2026; | ||
| day.value = "01"; | ||
| month.value = "January"; | ||
| year.value = new Date().getFullYear(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed this line (instead of hard-coding it to a year)
to-do-notifications/index.html
Outdated
| <option value="2018">2018</option> | ||
| <option value="2019">2019</option> | ||
| <option value="2020">2020</option> | ||
| <option value="2021">2021</option> | ||
| <option value="2022">2022</option> | ||
| <option value="2023">2023</option> | ||
| <option value="2024">2024</option> | ||
| <option value="2025">2025</option> | ||
| <option value="2026">2026</option> | ||
| <option value="2027">2027</option> | ||
| <option value="2028">2028</option> | ||
| <option value="2029">2029</option> | ||
| <option value="2030">2030</option> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reordered this list to be in ascending order
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you 😊
I have another idea: we can avoid changing the dates altogether, even in 2030!
This will generate a list of 13 options, starting with the current year (2026–2038)
// Populate year options: current year and 12 years into the future
const currentYear = new Date().getFullYear();
for (let i = 0; i <= 12; i++) {
const option = document.createElement("option");
const yearValue = currentYear + i;
option.value = yearValue;
option.textContent = yearValue;
year.appendChild(option);
}And then we set it:
year.value = currentYear;I would remove all the pre-filled years from HTML too and leave the <select> empty.
I wish I could’ve suggested it, but GitHub won’t allow it 🥲
|
Sorry it took me a while to get back to this task. I've added 2 more files to this PR:
I'll open a content PR to make sure the tutorial there reflects the same code. |
This is a follow up to #371, which was loading 2030 as the starting year in the form, picking from the first option in the HTML drop-down list.
This PR:
Motivation
To avoid future updates to this UI every time the year changes
Additional details
The app link can be accessed at https://mdn.github.io/dom-examples/to-do-notifications/