Skip to content

Commit

Permalink
dynamic options controlled
Browse files Browse the repository at this point in the history
  • Loading branch information
brkcvn committed Oct 5, 2022
1 parent 4e69883 commit e80e9b5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 10 deletions.
52 changes: 42 additions & 10 deletions resources/assets/js/components/AkauntingSelect.vue
Expand Up @@ -299,6 +299,11 @@ export default {
default: '',
description: "Selectbox input search placeholder text"
},
selectedControl: {
type: [Boolean, String],
default: false,
},
},
data() {
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -949,7 +956,6 @@ export default {
dynamicOptions: function(options) {
this.sorted_options = [];
this.selected = '';
if (this.group) {
// Option set sort_option data
Expand Down Expand Up @@ -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 = '';
}
}
}
},
},
Expand Down
6 changes: 6 additions & 0 deletions resources/views/components/form/group/select.blade.php
Expand Up @@ -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) }}"
Expand Down

0 comments on commit e80e9b5

Please sign in to comment.