From e80e9b5f3434bc51b575c471e5ede89d9b0ca705 Mon Sep 17 00:00:00 2001 From: Burak Civan Date: Wed, 5 Oct 2022 09:59:37 +0300 Subject: [PATCH] dynamic options controlled --- .../assets/js/components/AkauntingSelect.vue | 52 +++++++++++++++---- .../components/form/group/select.blade.php | 6 +++ 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/resources/assets/js/components/AkauntingSelect.vue b/resources/assets/js/components/AkauntingSelect.vue index 4aa377ea4..bfce3274e 100644 --- a/resources/assets/js/components/AkauntingSelect.vue +++ b/resources/assets/js/components/AkauntingSelect.vue @@ -299,6 +299,11 @@ export default { default: '', description: "Selectbox input search placeholder text" }, + + selectedControl: { + type: [Boolean, String], + default: false, + }, }, data() { @@ -882,18 +887,20 @@ export default { let is_string = false; let pre_value = []; - selected.forEach(item => { - if (typeof item != 'string') { - is_string = true; + if (selected !== undefined) { + 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; + if (is_string) { + this.selected = pre_value; + } } } } @@ -949,7 +956,6 @@ export default { dynamicOptions: function(options) { this.sorted_options = []; - this.selected = ''; if (this.group) { // Option set sort_option data @@ -1018,6 +1024,32 @@ 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); + } else { + this.selected = []; + } + }, this); + } else { + if (! options.find(option => option == this.selected)) { + this.selected = []; + } + } + } else { + if (this.multiple) { + this.selected = []; + } else { + this.selected = ''; + } + } } }, }, diff --git a/resources/views/components/form/group/select.blade.php b/resources/views/components/form/group/select.blade.php index ff2c421ed..be60b9a8d 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['selected-control'])) + selected-control + @elseif (! empty($selectedControl)) + selected-control + @endif + @if (empty($multiple)) @if (isset($selected) || old($name)) value="{{ old($name, $selected) }}"