dynamic options function refactoring

This commit is contained in:
Burak Civan 2022-10-06 14:36:44 +03:00
parent 3cab2fee8b
commit fdd00f666c
3 changed files with 58 additions and 27 deletions

View File

@ -300,7 +300,7 @@ export default {
description: "Selectbox input search placeholder text"
},
selectedControl: {
dynamicOptionsValueCheck: {
type: [Boolean, String],
default: false,
},
@ -869,6 +869,31 @@ export default {
this.setSortedOptions();
}
},
dynamicOptionsValue(options) {
if (this.dynamicOptionsValueCheck) {
if (this.multiple) {
let selected = this.selected;
this.selected = [];
selected.forEach(function (select, index) {
if (this.sorted_options.find((option) => option.key == select)) {
this.selected.push(select);
}
}, this);
} else {
if (!options.find((option) => option == this.selected)) {
this.selected = null;
}
}
} else {
if (this.multiple) {
this.selected = [];
} else {
this.selected = null;
}
}
}
},
watch: {
@ -1024,28 +1049,7 @@ export default {
}, this);
}
if (this.selectedControl) {
if (this.multiple) {
let selected = this.selected;
this.selected = [];
selected.forEach(function (select, index) {
if (this.sorted_options.find(option => option.key == select)) {
this.selected.push(select);
}
}, this);
} else {
if (! options.find(option => option == this.selected)) {
this.selected = null;
}
}
} else {
if (this.multiple) {
this.selected = [];
} else {
this.selected = null;
}
}
this.dynamicOptionsValue(options);
}
},
},

View File

@ -1089,6 +1089,31 @@ export default {
},
},
dynamicOptionsValue(options) {
if (this.dynamicOptionsValueCheck) {
if (this.multiple) {
let selected = this.selected;
this.selected = [];
selected.forEach(function (select, index) {
if (this.sorted_options.find((option) => option.key == select)) {
this.selected.push(select);
}
}, this);
} else {
if (!options.find((option) => option == this.selected)) {
this.selected = null;
}
}
} else {
if (this.multiple) {
this.selected = [];
} else {
this.selected = null;
}
}
},
watch: {
selected: function (selected) {
if (!this.multiple) {
@ -1237,6 +1262,8 @@ export default {
}
}, this);
}
this.dynamicOptionsValue(options);
}
},
},

View File

@ -65,10 +65,10 @@
search-text="{{ $searchText }}"
@endif
@if (! empty($attributes['selected-control']))
selected-control
@elseif (! empty($selectedControl))
selected-control
@if (! empty($attributes['dynamic-options-value-check']))
dynamic-options-value-check
@elseif (! empty($dynamicOptionsValueCheck))
dynamic-options-value-check
@endif
@if (empty($multiple))