Skip to content

Commit

Permalink
EZP-30164: After removing option from ezselection it it not possible …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
ViniTou authored and Łukasz Serwatka committed Mar 13, 2019
1 parent 40d7d3b commit 2e4261c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@
{{ form_errors(form.options) }}
<ul
class="ezselection-settings-option-list ez-selection-table list-unstyled"
data-selection-buttons=".ezselection-settings-option-remove">
data-selection-buttons=".ezselection-settings-option-remove"
data-next-option-id="{{ form.options.vars.value is empty ? 0 : max(form.options.vars.value|keys) + 1 }}">
{% for option in form.options %}
<li class="ezselection-settings-option-value ez-selection-table-row mb-2 d-flex align-items-center">
<input
Expand Down

0 comments on commit 2e4261c

Please sign in to comment.