From fc97798d0b0912740ad585db0a48e231fd586319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Fri, 3 Jul 2020 12:24:37 +0300 Subject: [PATCH] refs #1511 multi_select_remote_group fixes --- .../js/components/AkauntingSelectRemote.vue | 74 +++++++++++++++---- .../form/multi_select_remote_group.blade.php | 4 +- 2 files changed, 62 insertions(+), 16 deletions(-) diff --git a/resources/assets/js/components/AkauntingSelectRemote.vue b/resources/assets/js/components/AkauntingSelectRemote.vue index da8f3bff2..aa87a358b 100644 --- a/resources/assets/js/components/AkauntingSelectRemote.vue +++ b/resources/assets/js/components/AkauntingSelectRemote.vue @@ -480,14 +480,14 @@ export default { }, value: { type: [String, Number, Array], - default: null, + default: '', description: "Selectbox selected value" }, options: null, model: { type: [String, Number], - default: '', + default: null, description: "Selectbox selected model" }, @@ -598,10 +598,22 @@ export default { }, mounted() { - this.real_model = this.value; - if (this.multiple && !this.real_model.length) { - this.real_model = []; + if (this.multiple) { + if (!this.value.length) { + this.real_model = []; + } else { + let pre_value = []; + + this.value.forEach(item => { + pre_value.push(item.toString()); + }); + + this.real_model = pre_value; + } + + } else { + this.real_model = this.value; } this.$emit('interface', this.real_model); @@ -650,21 +662,27 @@ export default { }, change() { - if (typeof(this.real_model) === 'object') { + if (typeof(this.real_model) === 'object' && !Array.isArray(this.real_model)) { + return false; + } + + if (Array.isArray(this.real_model) && !this.real_model.length) { return false; } this.$emit('interface', this.real_model); this.$emit('change', this.real_model); - this.selectOptions.forEach(item => { - if (item.id == this.real_model) { - this.$emit('label', item.name); - this.$emit('option', item); + if (Array.isArray(this.selectOptions)) { + this.selectOptions.forEach(item => { + if (item.id == this.real_model) { + this.$emit('label', item.name); + this.$emit('option', item); - return true; - } - }); + return true; + } + }); + } }, onPressEnter() { @@ -887,9 +905,37 @@ export default { } }, + real_model: function (value) { + if (this.multiple) { + return; + } + + if (this.real_model != value) { + this.change(); + } + + let e = $.Event('keyup'); + e.keyCode= 9; // tab + $('#' + this.name).trigger(e); + + let event = new window.KeyboardEvent('keydown', { keyCode: 9 }); // Tab key + + window.dispatchEvent(event); + }, + value: function (value) { if (this.multiple) { - this.real_model = value; + if (Array.isArray(this.real_model) && !this.real_model.length) { + this.real_model = value; + } else { + let pre_value = []; + + value.forEach(item => { + pre_value.push(item.toString()); + }); + + this.real_model = pre_value; + } } else { //this.real_model = value.toString(); this.real_model = value; diff --git a/resources/views/partials/form/multi_select_remote_group.blade.php b/resources/views/partials/form/multi_select_remote_group.blade.php index 44eff83d1..699dcb591 100644 --- a/resources/views/partials/form/multi_select_remote_group.blade.php +++ b/resources/views/partials/form/multi_select_remote_group.blade.php @@ -17,7 +17,7 @@ name="{{ $name }}" :options="{{ json_encode($values) }}" - @if (isset($selected) || old($name)) + @if (!empty($selected) || old($name)) :value="{{ json_encode(old($name, $selected)) }}" @endif @@ -62,7 +62,7 @@ @endif remote-action="{{ $attributes['remote_action'] }}" - remote-type="'{{ $attributes['remote_type'] }}" + remote-type="{{ $attributes['remote_type'] }}" @if (!empty($attributes['currecny_code'])) currency-code="{{ $attributes['currecny_code'] }}"