From 2e4261caf459a2ae81ad1f994d8402405e54d47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Parafi=C5=84ski?= Date: Wed, 13 Mar 2019 12:29:35 +0100 Subject: [PATCH] EZP-30164: After removing option from ezselection it it not possible to add more options (#894) * EZP-30164: After removing option from ezselection it it not possible to add more options * EZP-30164: move id to data attr * EZP-30164: Move data attr to parent --- .../public/js/scripts/admin.contenttype.selection.js | 8 ++++---- .../views/admin/content_type/field_types.html.twig | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/bundle/Resources/public/js/scripts/admin.contenttype.selection.js b/src/bundle/Resources/public/js/scripts/admin.contenttype.selection.js index 47b90c4f53..6ee9b7af60 100644 --- a/src/bundle/Resources/public/js/scripts/admin.contenttype.selection.js +++ b/src/bundle/Resources/public/js/scripts/admin.contenttype.selection.js @@ -7,7 +7,6 @@ const NUMBER_PLACEHOLDER = /__number__/g; [...doc.querySelectorAll('.ezselection-settings.options')].forEach(container => { - const countExistingOptions = () => container.querySelectorAll(SELECTOR_OPTION).length; const findCheckedOptions = () => [...container.querySelectorAll('.ezselection-settings-option-checkbox:checked')]; const toggleDisableState = () => { const disabledState = !!findCheckedOptions().length; @@ -17,10 +16,11 @@ }; const addOption = () => { const template = container.querySelector(SELECTOR_TEMPLATE).innerHTML; + const optionsList = container.querySelector(SELECTOR_OPTIONS_LIST); + const nextId = parseInt(optionsList.dataset.nextOptionId, 10); - container - .querySelector(SELECTOR_OPTIONS_LIST) - .insertAdjacentHTML('beforeend', template.replace(NUMBER_PLACEHOLDER, countExistingOptions())); + optionsList.dataset.nextOptionId = nextId + 1; + optionsList.insertAdjacentHTML('beforeend', template.replace(NUMBER_PLACEHOLDER, nextId)); }; const removeOptions = () => { findCheckedOptions().forEach(element => element.closest(SELECTOR_OPTION).remove()); diff --git a/src/bundle/Resources/views/admin/content_type/field_types.html.twig b/src/bundle/Resources/views/admin/content_type/field_types.html.twig index 51f9fa9c0d..fdbdc15702 100644 --- a/src/bundle/Resources/views/admin/content_type/field_types.html.twig +++ b/src/bundle/Resources/views/admin/content_type/field_types.html.twig @@ -204,7 +204,8 @@ {{ form_errors(form.options) }}