- Issue created by @pjotr.savitski
- Merge request !8Already selected options will still be sepected after field updates. → (Open) created by pjotr.savitski
Selected values are not kept if field formatter is set to select.
Create a dependent field that uses a select fromatter and allow multiple values. Select options in both fields, then change selected values in the main/parent one. The dependent field will be updated, yet the selected options that are also present in new values are not marked as selected. It seems that there is a code that does that for other formatters like radios and checkboxes.
There is a need to extract the selected values before the update occurs and make any newly added options selected where the value matches. Most of the code is already present for other formatters.
if (element !== null) {
// XXX CUSTOM START
optionsArray = Array.prototype.slice.call(element.options)
currentSelection = optionsArray
.filter(option => option.selected)
.map(option => option.value)
// XXX CUSTOM END
element.options.length = 0
for (var i = 0; i <= options.length; i++) {
if (options.hasOwnProperty(i)) {
element.options.add(new Option(options[i].value, options[i].key))
// XXX CUSTOM START
if (currentSelection.includes(options[i].key.toString())) {
element.options[i].setAttribute('selected', 'selected')
}
// XXX CUSTOM END
}
}
}
Make a patch and commit it to the merge request branch.
The matching selected options will still remain selected as they are expected to.
None.
None.
Active
1.0
Code