mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-11 02:48:21 +00:00
Prevented EnumInput from remembering inapplicable values
This commit is contained in:
parent
84488b3e63
commit
43454b1641
1 changed files with 10 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Index, MaybeIndex, equals } from '../../util';
|
import { Index, MaybeIndex, equals, variantOf } from '../../util';
|
||||||
import { Fields } from './NicerForm.vue';
|
import { Fields } from './NicerForm.vue';
|
||||||
|
|
||||||
export type Variant = {
|
export type Variant = {
|
||||||
|
@ -34,7 +34,7 @@ const emit = defineEmits<{
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
// Local Variables for Two-Way bindings
|
// Local Variables for Two-Way bindings
|
||||||
let modelValue: MaybeEnumValue = $ref(null);
|
let modelValue = $ref(null as MaybeEnumValue);
|
||||||
// Sync from v-model
|
// Sync from v-model
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
watch(() => props.modelValue, (val) => {
|
watch(() => props.modelValue, (val) => {
|
||||||
|
@ -49,8 +49,14 @@ onMounted(() => {
|
||||||
}, { deep: true, immediate: true });
|
}, { deep: true, immediate: true });
|
||||||
});
|
});
|
||||||
// Sync to v-model
|
// Sync to v-model
|
||||||
watch($$(modelValue), (val) => {
|
watch($$(modelValue), (val, oldVal) => {
|
||||||
if (equals(val, props.modelValue)) return;
|
if (equals(val, props.modelValue)) return;
|
||||||
|
const [oldVariant, newVariant] = [variantOf(oldVal), variantOf(val)];
|
||||||
|
// Wipe variant values if variant definitions change
|
||||||
|
if (typeof val === 'object'
|
||||||
|
&& val && newVariant && oldVariant
|
||||||
|
&& !equals(props.variants[newVariant].fields, props.variants[oldVariant].fields))
|
||||||
|
val[newVariant] = formValue = {};
|
||||||
emit('update:modelValue', typeof val === 'string' ? val : Object.assign({}, val));
|
emit('update:modelValue', typeof val === 'string' ? val : Object.assign({}, val));
|
||||||
}, { deep: true });
|
}, { deep: true });
|
||||||
|
|
||||||
|
@ -88,4 +94,4 @@ watchEffect(() => {
|
||||||
border: 1px solid var(--cl-fg);
|
border: 1px solid var(--cl-fg);
|
||||||
padding: calc(0.25rem - 1px);
|
padding: calc(0.25rem - 1px);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Add table
Reference in a new issue