diff --git a/src/runtime/components/forms/Input.vue b/src/runtime/components/forms/Input.vue index 73dacb9fe5..d9b37d9239 100644 --- a/src/runtime/components/forms/Input.vue +++ b/src/runtime/components/forms/Input.vue @@ -158,7 +158,7 @@ export default defineComponent({ default: () => ({}) }, modelModifiers: { - type: Object as PropType<{ trim?: boolean, lazy?: boolean, number?: boolean }>, + type: Object as PropType<{ trim?: boolean, lazy?: boolean, number?: boolean, nullify?: boolean }>, default: () => ({}) } }, @@ -172,7 +172,7 @@ export default defineComponent({ const size = computed(() => sizeButtonGroup.value ?? sizeFormGroup.value) - const modelModifiers = ref(defu({}, props.modelModifiers, { trim: false, lazy: false, number: false })) + const modelModifiers = ref(defu({}, props.modelModifiers, { trim: false, lazy: false, number: false, nullify: false })) const input = ref(null) @@ -193,6 +193,10 @@ export default defineComponent({ value = looseToNumber(value) } + if (modelModifiers.value.nullify) { + value ||= null + } + emit('update:modelValue', value) emitFormInput() } diff --git a/src/runtime/components/forms/Textarea.vue b/src/runtime/components/forms/Textarea.vue index 921f05e6f0..cded07219a 100644 --- a/src/runtime/components/forms/Textarea.vue +++ b/src/runtime/components/forms/Textarea.vue @@ -127,7 +127,7 @@ export default defineComponent({ default: () => ({}) }, modelModifiers: { - type: Object as PropType<{ trim?: boolean, lazy?: boolean, number?: boolean }>, + type: Object as PropType<{ trim?: boolean, lazy?: boolean, number?: boolean, nullify?: boolean }>, default: () => ({}) } }, @@ -137,7 +137,7 @@ export default defineComponent({ const { emitFormBlur, emitFormInput, inputId, color, size, name } = useFormGroup(props, config) - const modelModifiers = ref(defu({}, props.modelModifiers, { trim: false, lazy: false, number: false })) + const modelModifiers = ref(defu({}, props.modelModifiers, { trim: false, lazy: false, number: false, nullify: false })) const textarea = ref(null) @@ -183,6 +183,10 @@ export default defineComponent({ value = looseToNumber(value) } + if (modelModifiers.value.nullify) { + value ||= null + } + emit('update:modelValue', value) emitFormInput() }