Default to null in forms if interface itself has no default value (#18610)

* Default to null in forms if interface itself has no default value

* Remove unecessary default values

* Create nervous-humans-leave.md
This commit is contained in:
Pascal Jufer
2023-05-15 22:34:31 +02:00
committed by GitHub
parent 0955e7fca2
commit 56ef14f82a
2 changed files with 13 additions and 17 deletions

View File

@@ -0,0 +1,5 @@
---
"@directus/app": patch
---
Fixed issue with interface forms not rendering when interface itself has no default value

View File

@@ -14,7 +14,7 @@
:autofocus="disabled !== true && autofocus"
:disabled="disabled"
:loading="loading"
:value="modelValue === undefined ? field.schema?.default_value : modelValue"
:value="value"
:width="(field.meta && field.meta.width) || 'full'"
:type="field.type"
:collection="field.collection"
@@ -34,7 +34,7 @@
<interface-system-raw-editor
v-else-if="rawEditorEnabled && rawEditorActive"
:value="modelValue === undefined ? field.schema?.default_value : modelValue"
:value="value"
:type="field.type"
@input="$emit('update:modelValue', $event)"
/>
@@ -52,7 +52,7 @@ import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import type { FormField } from './types';
interface Props {
const props = defineProps<{
field: FormField;
batchMode?: boolean;
batchActive?: boolean;
@@ -64,20 +64,7 @@ interface Props {
rawEditorEnabled?: boolean;
rawEditorActive?: boolean;
direction?: string;
}
const props = withDefaults(defineProps<Props>(), {
batchMode: false,
batchActive: false,
primaryKey: null,
modelValue: undefined,
loading: false,
disabled: false,
autofocus: false,
rawEditorEnabled: false,
rawEditorActive: false,
direction: undefined,
});
}>();
defineEmits(['update:modelValue', 'setFieldValue']);
@@ -95,6 +82,10 @@ const componentName = computed(() => {
? `interface-${props.field.meta.interface}`
: `interface-${getDefaultInterfaceForType(props.field.type!)}`;
});
const value = computed(() =>
props.modelValue === undefined ? props.field.schema?.default_value ?? null : props.modelValue
);
</script>
<style lang="scss" scoped>