Auto reset value when options updated on select dropdown interface (#23007)

Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
SP12893678
2024-07-15 23:17:15 +08:00
committed by GitHub
parent edcdcfc09d
commit 33fc00192e
3 changed files with 23 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"@directus/app": patch
---
Added auto reset of value to dropdown interface after conditional update of options

View File

@@ -1,8 +1,8 @@
<script setup lang="ts">
import { computed } from 'vue';
import { i18n } from '@/lang';
import { isEmpty, isEqual } from 'lodash';
import { computed, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { isEmpty } from 'lodash';
type Option = {
text: string;
@@ -27,7 +27,7 @@ const props = withDefaults(
},
);
defineEmits(['input']);
const emit = defineEmits(['input']);
const { t } = useI18n();
@@ -66,6 +66,20 @@ const showGlobalIcon = computed(() => {
return false;
});
watch(
() => props.choices,
(newChoices, oldChoices) => {
if (
props.value !== null &&
!isEqual(newChoices, oldChoices) &&
!newChoices?.some((choice) => choice.value === props.value)
) {
// Reset if the options have dynamically changed and the current value is not available anymore
emit('input', null);
}
},
);
</script>
<template>

View File

@@ -141,3 +141,4 @@
- Dominic-Preap
- brandondrew
- alantiller
- SP12893678