Fix clear value for fields with default when creating an item

This commit is contained in:
Nicola Krumschmidt
2021-01-14 15:51:19 +01:00
parent fb401c104b
commit 0dd271bf09

View File

@@ -118,10 +118,17 @@ export default defineComponent({
return false;
});
const defaultValue = computed(() => {
const value = props.field.schema?.default_value;
if (value !== undefined) return value;
return null;
});
const _value = computed(() => {
if (props.value !== undefined) return props.value;
if (props.initialValue !== undefined) return props.initialValue;
return props.field.schema?.default_value;
return defaultValue.value;
});
const { showRaw, rawValue } = useRaw();
@@ -129,7 +136,10 @@ export default defineComponent({
return { isDisabled, marked, _value, emitValue, showRaw, rawValue };
function emitValue(value: any) {
if (isEqual(value, props.initialValue) || (value === null && props.initialValue === undefined)) {
if (
isEqual(value, props.initialValue) ||
(props.initialValue === undefined && isEqual(value, defaultValue.value))
) {
emit('unset', props.field);
} else {
emit('input', value);