Skip to content
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

fix(storefront): SD-10928 Cornerstone update to support multiple date fields and remove blank space #2533

Merged
merged 1 commit into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Use fetch when updating variants in cart [#2521](https://github.com/bigcommerce/cornerstone/pull/2521)
- Add a region to display the payment promotion widget on the category pages [#2530](https://github.com/bigcommerce/cornerstone/pull/2530)
- Rename the region to display the payment promotion widget on the category pages [#2531](https://github.com/bigcommerce/cornerstone/pull/2531)
- Cornerstone update to support multiple date fields and remove blank space [#2533](https://github.com/bigcommerce/cornerstone/pull/2533)

## 6.15.0 (10-18-2024)
- Cornerstone changes to support inc/ex tax price lists on PDP [#2486](https://github.com/bigcommerce/cornerstone/pull/2486)
Expand Down
42 changes: 26 additions & 16 deletions assets/js/theme/common/product-details.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,14 +594,13 @@ export default class ProductDetails extends ProductDetailsBase {
}

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);
this.$scope.each((i, scope) => {
function updateDays(dateOption) {
const monthSelector = dateOption.querySelector('select[name$="[month]"]');
const daySelector = dateOption.querySelector('select[name$="[day]"]');
const yearSelector = dateOption.querySelector('select[name$="[year]"]');
const month = parseInt(monthSelector.value, 10);
const year = parseInt(yearSelector.value, 10);
let daysInMonth;

if (!Number.isNaN(month) && !Number.isNaN(year)) {
Expand All @@ -616,17 +615,28 @@ export default class ProductDetails extends ProductDetailsBase {
daysInMonth = 31;
}

daySelector.empty();

for (let i = 1; i <= daysInMonth; i++) {
daySelector.append($('<option></option>').val(i).text(i));
for (let day = 29; day <= 31; day++) {
const option = daySelector.querySelector(`option[value="${day}"]`);
if (day <= daysInMonth && !option) {
daySelector.options.add(new Option(day, day));
} else if (day > daysInMonth && option) {
option.remove();
}
}
}
};
}

$(scope).on('change', (e) => {
const dateOption = e.target && e.target.closest && e.target.closest('[data-product-attribute=date]');

monthSelector.on('change', updateDays);
yearSelector.on('change', updateDays);
updateDays();
if (dateOption) {
updateDays(dateOption);
}
});

scope.querySelectorAll('[data-product-attribute=date]').forEach(dateOption => {
updateDays(dateOption);
});
});
}
}
6 changes: 2 additions & 4 deletions templates/components/products/options/date.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{{> components/common/requireness-msg}}
</label>
<select class="form-select form-select--date" name="attribute[{{this.id}}][year]" id="year-selector" {{#if required}}required{{/if}}>
<select class="form-select form-select--date" name="attribute[{{this.id}}][year]" {{#if required}}required{{/if}}>
<option value="">{{lang 'common.year'}}</option>
{{#for earliest_year latest_year}}
<option value="{{$index}}" {{#if ../selected_date.year '==' $index}}selected="selected"{{/if}}>
Expand All @@ -15,7 +15,7 @@
<option value="{{earliest_year}}" selected="selected">{{earliest_year}}</option>
{{/if}}
</select>
<select class="form-select form-select--date" name="attribute[{{this.id}}][month]" id="month-selector" {{#if required}}required{{/if}}>
<select class="form-select form-select--date" name="attribute[{{this.id}}][month]" {{#if required}}required{{/if}}>
<option value="">{{lang 'common.month'}}</option>
{{#for 1 12}}
<option value="{{$index}}" {{#if ../selected_date.month '==' $index}}selected="selected"{{/if}}>
Expand All @@ -25,12 +25,10 @@
</select>
<select class="form-select form-select--date" name="attribute[{{this.id}}][day]" {{#if required}}required{{/if}}>
<option value="">{{lang 'common.day'}}</option>
<optgroup id="day-selector">
{{#for 1 31}}
<option value="{{$index}}" {{#if ../selected_date.day '==' $index}}selected="selected"{{/if}}>
{{$index}}
</option>
{{/for}}
</optgroup>
</select>
</div>
Loading