Skip to content

Commit

Permalink
bug #13547 [Promotion] Fix js errors associated with actions/rules/sc…
Browse files Browse the repository at this point in the history
…opes (GSadee)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | 1.11
| Bug fix?        | yes
| New feature?    | no
| BC breaks?      | no
| Deprecations?   | no
| Related tickets | fixes #13447
| License         | MIT

<!--
 - Bug fixes must be submitted against the 1.10 or 1.11 branch(the lowest possible)
 - Features and deprecations must be submitted against the master branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------

9f86619 [Promotion] Fix js errors associated with actions/rules/scopes
  • Loading branch information
lchrusciel committed Jan 27, 2022
2 parents 039d249 + 9f86619 commit 2f876d2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/Sylius/Bundle/AdminBundle/Resources/private/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,7 @@ $(document).ready(() => {
});
$('#sylius_promotion_rules > a[data-form-collection="add"]').on('click', () => {
setTimeout(() => {
$(`select[name^="sylius_promotion[rules]"][name$="[type]"]`).last().change();
}, 50);
});
$('#sylius_catalog_promotion_actions > a[data-form-collection="add"]').on('click', () => {
setTimeout(() => {
$('select[name^="sylius_catalog_promotion[actions]"][name$="[type]"]').last().change();
}, 50);
});
$('#sylius_catalog_promotion_scopes > a[data-form-collection="add"]').on('click', () => {
setTimeout(() => {
$(`select[name^="sylius_catalog_promotion[scopes]"][name$="[type]"]`).last().change();
$('select[name^="sylius_promotion[rules]"][name$="[type]"]').last().change();
}, 50);
});

Expand All @@ -89,13 +79,17 @@ $(document).ready(() => {
}
});

$(document).loadCatalogPromotionScopeConfiguration(
document.querySelector('#sylius_catalog_promotion_scopes [data-form-collection="item"]:last-child')
);
if ($('#sylius_catalog_promotion_scopes').length > 0) {
$(document).loadCatalogPromotionScopeConfiguration(
document.querySelector('#sylius_catalog_promotion_scopes [data-form-collection="item"]:last-child')
);
}

$(document).loadCatalogPromotionActionConfiguration(
document.querySelector('#sylius_catalog_promotion_actions [data-form-collection="item"]:last-child')
);
if ($('#sylius_catalog_promotion_actions').length > 0) {
$(document).loadCatalogPromotionActionConfiguration(
document.querySelector('#sylius_catalog_promotion_actions [data-form-collection="item"]:last-child')
);
}
});
$(document).on('collection-form-update', () => {
$('.sylius-autocomplete').each((index, element) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import $ from 'jquery';

$.fn.extend({
loadCatalogPromotionActionConfiguration(target) {
if (target == null || target.querySelector('#sylius_catalog_promotion_actions select[name*="type"]') == null) {
return;
}

target.querySelector('#sylius_catalog_promotion_actions select[name*="type"]').onchange = function () {
const parent = this.parentElement;
const newConfig = document.createElement('div');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import $ from 'jquery';

$.fn.extend({
loadCatalogPromotionScopeConfiguration(target) {
if (target == null || target.querySelector('#sylius_catalog_promotion_scopes select[name*="type"]') == null) {
return;
}

target.querySelector('#sylius_catalog_promotion_scopes select[name*="type"]').onchange = function () {
const parent = this.parentElement;
const newConfig = document.createElement('div');
Expand Down

0 comments on commit 2f876d2

Please sign in to comment.