refs #1511 multi_select_remote_group fixes

This commit is contained in:
Cüneyt Şentürk 2020-07-03 12:24:37 +03:00
parent a96d6f22bc
commit fc97798d0b
2 changed files with 62 additions and 16 deletions

View File

@ -480,14 +480,14 @@ export default {
}, },
value: { value: {
type: [String, Number, Array], type: [String, Number, Array],
default: null, default: '',
description: "Selectbox selected value" description: "Selectbox selected value"
}, },
options: null, options: null,
model: { model: {
type: [String, Number], type: [String, Number],
default: '', default: null,
description: "Selectbox selected model" description: "Selectbox selected model"
}, },
@ -598,10 +598,22 @@ export default {
}, },
mounted() { mounted() {
this.real_model = this.value;
if (this.multiple && !this.real_model.length) { if (this.multiple) {
this.real_model = []; 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); this.$emit('interface', this.real_model);
@ -650,21 +662,27 @@ export default {
}, },
change() { 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; return false;
} }
this.$emit('interface', this.real_model); this.$emit('interface', this.real_model);
this.$emit('change', this.real_model); this.$emit('change', this.real_model);
this.selectOptions.forEach(item => { if (Array.isArray(this.selectOptions)) {
if (item.id == this.real_model) { this.selectOptions.forEach(item => {
this.$emit('label', item.name); if (item.id == this.real_model) {
this.$emit('option', item); this.$emit('label', item.name);
this.$emit('option', item);
return true; return true;
} }
}); });
}
}, },
onPressEnter() { 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) { value: function (value) {
if (this.multiple) { 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 { } else {
//this.real_model = value.toString(); //this.real_model = value.toString();
this.real_model = value; this.real_model = value;

View File

@ -17,7 +17,7 @@
name="{{ $name }}" name="{{ $name }}"
:options="{{ json_encode($values) }}" :options="{{ json_encode($values) }}"
@if (isset($selected) || old($name)) @if (!empty($selected) || old($name))
:value="{{ json_encode(old($name, $selected)) }}" :value="{{ json_encode(old($name, $selected)) }}"
@endif @endif
@ -62,7 +62,7 @@
@endif @endif
remote-action="{{ $attributes['remote_action'] }}" remote-action="{{ $attributes['remote_action'] }}"
remote-type="'{{ $attributes['remote_type'] }}" remote-type="{{ $attributes['remote_type'] }}"
@if (!empty($attributes['currecny_code'])) @if (!empty($attributes['currecny_code']))
currency-code="{{ $attributes['currecny_code'] }}" currency-code="{{ $attributes['currecny_code'] }}"