Dont clear groups field on first init

This commit is contained in:
philipp lang 2024-04-26 20:18:23 +02:00
parent b65ae906b2
commit 42c0ff065f
1 changed files with 15 additions and 7 deletions

View File

@ -54,15 +54,19 @@ const inner = computed({
const options = ref([]); const options = ref([]);
const disabled = ref(false); const disabled = ref(false);
async function refreshOptions() { async function refreshOptions(clear) {
if (props.field.parent_group === null && props.field.parent_field === null) { if (props.field.parent_group === null && props.field.parent_field === null) {
if (clear) {
emit('update:modelValue', null); emit('update:modelValue', null);
}
options.value = (await axios.get('/api/group?prefer_inner')).data.data; options.value = (await axios.get('/api/group?prefer_inner')).data.data;
disabled.value = false; disabled.value = false;
return; return;
} }
if (props.field.parent_group !== null) { if (props.field.parent_group !== null) {
if (clear) {
emit('update:modelValue', null); emit('update:modelValue', null);
}
options.value = (await axios.get('/api/group/' + props.field.parent_group + '?prefer_inner')).data.data; options.value = (await axios.get('/api/group/' + props.field.parent_group + '?prefer_inner')).data.data;
disabled.value = false; disabled.value = false;
return; return;
@ -74,24 +78,28 @@ async function refreshOptions() {
if (!props.payload[props.field.parent_field] || props.payload[props.field.parent_field] === -1) { if (!props.payload[props.field.parent_field] || props.payload[props.field.parent_field] === -1) {
options.value = []; options.value = [];
if (clear) {
emit('update:modelValue', null); emit('update:modelValue', null);
}
disabled.value = true; disabled.value = true;
return; return;
} }
if (clear) {
emit('update:modelValue', null); emit('update:modelValue', null);
}
options.value = (await axios.get('/api/group/' + props.payload[props.field.parent_field] + '?prefer_inner')).data.data; options.value = (await axios.get('/api/group/' + props.payload[props.field.parent_field] + '?prefer_inner')).data.data;
disabled.value = false; disabled.value = false;
} }
refreshOptions(); refreshOptions(false);
if (props.field.parent_field) { if (props.field.parent_field) {
watch( watch(
() => props.payload[props.field.parent_field], () => props.payload[props.field.parent_field],
function (oldValue, newValue) { function (oldValue, newValue) {
if (oldValue !== newValue) { if (oldValue !== newValue) {
refreshOptions(); refreshOptions(true);
} }
}, },
); );