Merge pull request #2656 from brkcvn/dynamic-options
Value checked on dynamic options for Select components
This commit is contained in:
commit
c288e7e8ce
@ -107,7 +107,7 @@
|
|||||||
|
|
||||||
<span slot="infoBlock" class="absolute right-8 top-3 bg-green text-white px-2 py-1 rounded-md text-xs" v-if="new_options[selected]">{{ addNew.new_text }}</span>
|
<span slot="infoBlock" class="absolute right-8 top-3 bg-green text-white px-2 py-1 rounded-md text-xs" v-if="new_options[selected]">{{ addNew.new_text }}</span>
|
||||||
|
|
||||||
<select :name="name" :id="name" v-model="selected" class="d-none">
|
<select :name="name" :id="name" class="hidden">
|
||||||
<option v-for="option in sortedOptions" :key="option.key" :value="option.key">{{ option.value }}</option>
|
<option v-for="option in sortedOptions" :key="option.key" :value="option.key">{{ option.value }}</option>
|
||||||
</select>
|
</select>
|
||||||
</base-input>
|
</base-input>
|
||||||
@ -299,6 +299,11 @@ export default {
|
|||||||
default: '',
|
default: '',
|
||||||
description: "Selectbox input search placeholder text"
|
description: "Selectbox input search placeholder text"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
dynamicOptionsValueCheck: {
|
||||||
|
type: [Boolean, String],
|
||||||
|
default: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
@ -350,7 +355,6 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
this.sorted_options.sort(this.sortBy(this.option_sortable));
|
this.sorted_options.sort(this.sortBy(this.option_sortable));
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.sorted_options;
|
return this.sorted_options;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -865,6 +869,31 @@ export default {
|
|||||||
this.setSortedOptions();
|
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: {
|
watch: {
|
||||||
@ -882,15 +911,17 @@ export default {
|
|||||||
let is_string = false;
|
let is_string = false;
|
||||||
let pre_value = [];
|
let pre_value = [];
|
||||||
|
|
||||||
selected.forEach(item => {
|
if (selected !== undefined && selected.length) {
|
||||||
if (typeof item != 'string') {
|
selected.forEach(item => {
|
||||||
is_string = true;
|
if (typeof item != 'string') {
|
||||||
|
is_string = true;
|
||||||
|
|
||||||
if (item != '') {
|
if (item != '') {
|
||||||
pre_value.push(item.toString());
|
pre_value.push(item.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
if (is_string) {
|
if (is_string) {
|
||||||
this.selected = pre_value;
|
this.selected = pre_value;
|
||||||
@ -949,11 +980,10 @@ export default {
|
|||||||
|
|
||||||
dynamicOptions: function(options) {
|
dynamicOptions: function(options) {
|
||||||
this.sorted_options = [];
|
this.sorted_options = [];
|
||||||
this.selected = '';
|
|
||||||
|
|
||||||
if (this.group) {
|
if (this.group) {
|
||||||
// Option set sort_option data
|
// Option set sort_option data
|
||||||
if (!Array.isArray(options)) {
|
if (! Array.isArray(options)) {
|
||||||
for (const [index, _options] of Object.entries(options)) {
|
for (const [index, _options] of Object.entries(options)) {
|
||||||
let values = [];
|
let values = [];
|
||||||
|
|
||||||
@ -991,7 +1021,7 @@ export default {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Option set sort_option data
|
// Option set sort_option data
|
||||||
if (!Array.isArray(options)) {
|
if (! Array.isArray(options)) {
|
||||||
for (const [key, value] of Object.entries(options)) {
|
for (const [key, value] of Object.entries(options)) {
|
||||||
this.sorted_options.push({
|
this.sorted_options.push({
|
||||||
key: key.toString(),
|
key: key.toString(),
|
||||||
@ -1018,6 +1048,8 @@ export default {
|
|||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.dynamicOptionsValue(options);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -104,7 +104,7 @@
|
|||||||
|
|
||||||
<span slot="infoBlock" class="absolute right-8 top-3 bg-green text-white px-2 py-1 rounded-md text-xs" v-if="new_options[selected]">{{ addNew.new_text }}</span>
|
<span slot="infoBlock" class="absolute right-8 top-3 bg-green text-white px-2 py-1 rounded-md text-xs" v-if="new_options[selected]">{{ addNew.new_text }}</span>
|
||||||
|
|
||||||
<select :name="name" :id="name" v-model="selected" class="d-none">
|
<select :name="name" :id="name" class="hidden">
|
||||||
<option v-for="option in sortedOptions" :key="option.key" :value="option.key">{{ option.value }}</option>
|
<option v-for="option in sortedOptions" :key="option.key" :value="option.key">{{ option.value }}</option>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@ -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: {
|
watch: {
|
||||||
selected: function (selected) {
|
selected: function (selected) {
|
||||||
if (!this.multiple) {
|
if (!this.multiple) {
|
||||||
@ -1237,6 +1262,8 @@ export default {
|
|||||||
}
|
}
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.dynamicOptionsValue(options);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -65,6 +65,12 @@
|
|||||||
search-text="{{ $searchText }}"
|
search-text="{{ $searchText }}"
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
@if (! empty($attributes['dynamic-options-value-check']))
|
||||||
|
dynamic-options-value-check
|
||||||
|
@elseif (! empty($dynamicOptionsValueCheck))
|
||||||
|
dynamic-options-value-check
|
||||||
|
@endif
|
||||||
|
|
||||||
@if (empty($multiple))
|
@if (empty($multiple))
|
||||||
@if (isset($selected) || old($name))
|
@if (isset($selected) || old($name))
|
||||||
value="{{ old($name, $selected) }}"
|
value="{{ old($name, $selected) }}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user