Hi,
in some forms, we use tags and load the available list of tags from a static list:
settingsfields:
type: fields
fields:
type: tags
label: Tags
accept: options
options:
type: api
url: "{{ site.url }}/tags.json"
if i add the same options in a table in the panel, i recive an error:
columns:
tags:
label: Tags
type: tags
options:
type: api
url: "{{ site.url }}/tags.json"
the problem is, that the preview is rendered by the vue component ‘k-tags-field-preview’, an this components expects that ‘options’ is an array and not a object.
Exists same other property for this, or is this feature not implemented?
i write my own extension, but a core solution would be better.
<script>
export default {
extends: "k-tags-field-preview",
created: function() {
var options = this.column?.options || this.field?.options || [];
if(Array.isArray(options)){
return;
}
options = this.column?.options;
if(!options || !options.type || options.type != "api" || !options.url){
return;
}
const url = '..' + options.url;
this.column.options = [];
this.$api.get(url).then((tags) => {
var tagsList = []
for (const [key, value] of Object.entries(tags)) {
tagsList.push({value: key.trim(), text: value});
}
this.column.options = tagsList;
});
},
computed: {
bubbles() {
let bubbles = this.value;
// predefined options
var options = this.column?.options || this.field?.options || [];
if (typeof bubbles === "string") {
bubbles = bubbles.split(",");
}
/*FIX: trim babble values*/
bubbles = bubbles.map( t => t.trim());
return bubbles.map((bubble) => {
if (typeof bubble === "string") {
bubble = {
value: bubble,
text: bubble,
};
}
for (const option of options) {
if (option.value == bubble.value) {
bubble.text = option.text;
}
}
return {
back: "light",
color: "black",
...bubble,
};
});
},
},
};
</script>