diff --git a/CHANGELOG.md b/CHANGELOG.md index 1d99d26ea7..0597795957 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Draft +- Date Field Modifier - February showing 30th and 31st [#2473](https://github.com/bigcommerce/cornerstone/pull/2473) - Adding mobile nav dropdown focusTrap [#2465](https://github.com/bigcommerce/cornerstone/pull/2465) - Remove remote_api_scripts to avoid double firing Meta Pixel analytics [#2467](https://github.com/bigcommerce/cornerstone/pull/2467) - Prevent flow outside page container on account pages [#2462](https://github.com/bigcommerce/cornerstone/pull/2462) diff --git a/assets/js/theme/common/product-details.js b/assets/js/theme/common/product-details.js index 94dd4ad329..7ef5c481cf 100644 --- a/assets/js/theme/common/product-details.js +++ b/assets/js/theme/common/product-details.js @@ -25,6 +25,7 @@ export default class ProductDetails extends ProductDetailsBase { this.swatchInitMessageStorage = {}; this.swatchGroupIdList = $('[id^="swatchGroup"]').map((_, group) => $(group).attr('id')); this.storeInitMessagesForSwatches(); + this.updateDateSelector(); const $form = $('form[data-cart-item-add]', $scope); @@ -591,4 +592,41 @@ export default class ProductDetails extends ProductDetailsBase { detail: { productDetails }, })); } + + updateDateSelector() { + $(document).ready(() => { + const monthSelector = $('#month-selector'); + const daySelector = $('#day-selector'); + const yearSelector = $('#year-selector'); + + const updateDays = () => { + const month = parseInt(monthSelector.val(), 10); + const year = parseInt(yearSelector.val(), 10); + let daysInMonth; + + if (!Number.isNaN(month) && !Number.isNaN(year)) { + switch (month) { + case 2: + daysInMonth = (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0) ? 29 : 28; + break; + case 4: case 6: case 9: case 11: + daysInMonth = 30; + break; + default: + daysInMonth = 31; + } + + daySelector.empty(); + + for (let i = 1; i <= daysInMonth; i++) { + daySelector.append($('').val(i).text(i)); + } + } + }; + + monthSelector.on('change', updateDays); + yearSelector.on('change', updateDays); + updateDays(); + }); + } } diff --git a/templates/components/products/options/date.html b/templates/components/products/options/date.html index 58e2b0286c..7972b2c2b1 100644 --- a/templates/components/products/options/date.html +++ b/templates/components/products/options/date.html @@ -4,7 +4,18 @@ {{> components/common/requireness-msg}} - + + {{#for earliest_year latest_year}} + + {{/for}} + {{#if earliest_year '==' latest_year}} + + {{/if}} + + -