diff --git a/resources/assets/js/components/AkauntingSelect.vue b/resources/assets/js/components/AkauntingSelect.vue index 4aa377ea4..2fa5c21a0 100644 --- a/resources/assets/js/components/AkauntingSelect.vue +++ b/resources/assets/js/components/AkauntingSelect.vue @@ -107,7 +107,7 @@ {{ addNew.new_text }} - @@ -299,6 +299,11 @@ export default { default: '', description: "Selectbox input search placeholder text" }, + + dynamicOptionsValueCheck: { + type: [Boolean, String], + default: false, + }, }, data() { @@ -350,7 +355,6 @@ export default { } else { this.sorted_options.sort(this.sortBy(this.option_sortable)); } - return this.sorted_options; }, }, @@ -865,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: { @@ -882,15 +911,17 @@ export default { let is_string = false; let pre_value = []; - selected.forEach(item => { - if (typeof item != 'string') { - is_string = true; + if (selected !== undefined && selected.length) { + selected.forEach(item => { + if (typeof item != 'string') { + is_string = true; - if (item != '') { - pre_value.push(item.toString()); + if (item != '') { + pre_value.push(item.toString()); + } } - } - }); + }); + } if (is_string) { this.selected = pre_value; @@ -949,11 +980,10 @@ export default { dynamicOptions: function(options) { this.sorted_options = []; - this.selected = ''; if (this.group) { // Option set sort_option data - if (!Array.isArray(options)) { + if (! Array.isArray(options)) { for (const [index, _options] of Object.entries(options)) { let values = []; @@ -991,7 +1021,7 @@ export default { } } else { // Option set sort_option data - if (!Array.isArray(options)) { + if (! Array.isArray(options)) { for (const [key, value] of Object.entries(options)) { this.sorted_options.push({ key: key.toString(), @@ -1018,6 +1048,8 @@ export default { } }, this); } + + this.dynamicOptionsValue(options); } }, }, diff --git a/resources/assets/js/components/AkauntingSelectRemote.vue b/resources/assets/js/components/AkauntingSelectRemote.vue index 56414fa39..c2c5f23d5 100644 --- a/resources/assets/js/components/AkauntingSelectRemote.vue +++ b/resources/assets/js/components/AkauntingSelectRemote.vue @@ -104,7 +104,7 @@ {{ addNew.new_text }} - @@ -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); } }, }, diff --git a/resources/views/components/form/group/select.blade.php b/resources/views/components/form/group/select.blade.php index ff2c421ed..52460a915 100644 --- a/resources/views/components/form/group/select.blade.php +++ b/resources/views/components/form/group/select.blade.php @@ -65,6 +65,12 @@ search-text="{{ $searchText }}" @endif + @if (! empty($attributes['dynamic-options-value-check'])) + dynamic-options-value-check + @elseif (! empty($dynamicOptionsValueCheck)) + dynamic-options-value-check + @endif + @if (empty($multiple)) @if (isset($selected) || old($name)) value="{{ old($name, $selected) }}"