-
Notifications
You must be signed in to change notification settings - Fork 57
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
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 #894
Conversation
return 0; | ||
} | ||
const lastInput = container.querySelector(SELECTOR_OPTIONS_LIST).lastElementChild.querySelector('input[type="text"]'); | ||
const lastId = parseInt(lastInput.name.match(/.+\[(\d)]$/)[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be stored in data-attribute. The same like @Nattfarinn did in ezmatrix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dew326
fixd
0b7ac0e
to
f51c826
Compare
{{ form_widget(option, { 'attr': { 'class': 'form-control ml-1 mb-0'}}) }} | ||
{{ form_widget(option, { 'attr': { | ||
'class': 'form-control ml-1 mb-0', | ||
'data-ezselection-option-id': option.vars.name }}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant more like adding data-attribute only to the parent ezselection-settings
like data-last-id={{ max(form.options|keys) }}
.
if (countExistingOptions() === 0) { | ||
return 0; | ||
} | ||
const lastInput = container.querySelector(SELECTOR_OPTIONS_LIST).lastElementChild.querySelector('input[type="text"]'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query will be much simpler if you use what is proposed in previous comment
const getNextId = () => { | ||
if (countExistingOptions() === 0) { | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after if there is always empty line
@@ -15,12 +15,21 @@ | |||
|
|||
container.querySelector(SELECTOR_BTN_REMOVE)[methodName]('disabled', disabledState); | |||
}; | |||
const getNextId = () => { | |||
if (countExistingOptions() === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use just !countExistingOptions()
const lastInput = container.querySelector(SELECTOR_OPTIONS_LIST).lastElementChild.querySelector('input[type="text"]'); | ||
const lastId = lastInput.dataset.ezselectionOptionId; | ||
|
||
return lastId + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the ezselectionOptionId
is '3' this will return '31'. I believe it's not what you want ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don;t know how I missed parseInt, it was here before :D
Could you merge it up? |
Instead of counting options, which creates problem with overlapping ids when prior to add option is removed, we use
id
extracted fromname
from last input.Checklist:
$ composer fix-cs
)