Skip to content

Commit

Permalink
IBX-6071: Handled custom attributes deselection (#104)
Browse files Browse the repository at this point in the history
* IBX-6071: Handled custom attributes deselection

* IBX-6071: CS

* IBX-6071: CS

* IBX-6071: Code cleanup

* IBX-6071: Code cleanup

* IBX-6071: CS

* IBX-6071: Applied review remark

* IBX-6071: CS

* IBX-6071: Rollbacked solution

* IBX-6071: Applied review remarks

* IBX-6071: Applied review remark

* IBX-6071: Applied review remark

* IBX-6071: Applied review remark

* IBX-6071: Fixed problem with selection when default value was empty
  • Loading branch information
barw4 authored Jul 21, 2023
1 parent a14863d commit 824548e
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ class IbexaCustomAttributesFormView extends View {
addListToDropdown(labeledDropdown.fieldView, itemsList);

this.listenTo(labeledDropdown.fieldView, 'execute', (event) => {
const alreadySelectedValues = labeledDropdown.fieldView.element.value ? labeledDropdown.fieldView.element.value.split(' ') : [];
const value = config.multiple ? [...new Set([...alreadySelectedValues, event.source.value])].join(' ') : event.source.value;
const value = this.getNewValue(event.source.value, config.multiple, labeledDropdown.fieldView.element.value);

labeledDropdown.fieldView.buttonView.set({
label: value,
Expand All @@ -227,6 +226,24 @@ class IbexaCustomAttributesFormView extends View {
return labeledDropdown;
}

getNewValue(clickedValue, multiple, previousValue = '') {
const selectedItems = previousValue ? new Set(previousValue.split(' ')) : new Set();

if (selectedItems.has(clickedValue)) {
selectedItems.delete(clickedValue);

return [...selectedItems].join(' ');
}

if (!multiple) {
selectedItems.clear();
}

selectedItems.add(clickedValue);

return [...selectedItems].join(' ');
}

createTextInput(config) {
const labeledInput = new LabeledFieldView(this.locale, createLabeledInputText);

Expand Down

0 comments on commit 824548e

Please sign in to comment.