Add new option "as_id" to Pick*DynamicType

This option will make the app return a single id of the entity in data, and not the entity json.
This commit is contained in:
2023-11-27 13:23:36 +01:00
parent 1a9af6b0b1
commit f11f7498d7
5 changed files with 30 additions and 8 deletions

View File

@@ -24,7 +24,8 @@ function loadDynamicPicker(element) {
(input.value === '[]' || input.value === '') ?
null : [ JSON.parse(input.value) ]
)
suggested = JSON.parse(el.dataset.suggested)
suggested = JSON.parse(el.dataset.suggested),
as_id = parseInt(el.dataset.asId) === 1;
if (!isMultiple) {
if (input.value === '[]'){
@@ -50,7 +51,8 @@ function loadDynamicPicker(element) {
types: JSON.parse(el.dataset.types),
picked: picked === null ? [] : picked,
uniqid: el.dataset.uniqid,
suggested: suggested
suggested: suggested,
as_id: as_id,
}
},
computed: {
@@ -69,7 +71,12 @@ function loadDynamicPicker(element) {
return el.type === entity.type && el.id === entity.id;
})) {
this.picked.push(entity);
input.value = JSON.stringify(this.picked);
if (!as_id) {
input.value = JSON.stringify(this.picked);
} else {
const ids = this.picked.map(el => el.id);
input.value = ids.join(',');
}
console.log(entity)
}
} else {
@@ -78,7 +85,11 @@ function loadDynamicPicker(element) {
})) {
this.picked.splice(0, this.picked.length);
this.picked.push(entity);
input.value = JSON.stringify(this.picked[0]);
if (!as_id) {
input.value = JSON.stringify(this.picked[0]);
} else {
input.value = this.picked.map(el => el.id);
}
}
}
},