mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Merge pull request #3690 from nickrum/create-item-reset-fix
Fix clear value for fields with default when creating an item
This commit is contained in:
@@ -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);
|
||||
@@ -189,10 +199,10 @@ export default defineComponent({
|
||||
|
||||
.note {
|
||||
display: block;
|
||||
max-width: 520px;
|
||||
margin-top: 4px;
|
||||
color: var(--foreground-subdued);
|
||||
font-style: italic;
|
||||
max-width: 520px;
|
||||
}
|
||||
|
||||
.invalid {
|
||||
|
||||
Reference in New Issue
Block a user