Skip to content

Commit

Permalink
feat(Input/Textarea): nullify model modifier (#2309)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerbuuun authored Oct 14, 2024
1 parent 33b9a44 commit 9dd7e61
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/runtime/components/forms/Input.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => ({})
}
},
Expand All @@ -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<HTMLInputElement | null>(null)
Expand All @@ -193,6 +193,10 @@ export default defineComponent({
value = looseToNumber(value)
}
if (modelModifiers.value.nullify) {
value ||= null
}
emit('update:modelValue', value)
emitFormInput()
}
Expand Down
8 changes: 6 additions & 2 deletions src/runtime/components/forms/Textarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => ({})
}
},
Expand All @@ -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<HTMLTextAreaElement | null>(null)
Expand Down Expand Up @@ -183,6 +183,10 @@ export default defineComponent({
value = looseToNumber(value)
}
if (modelModifiers.value.nullify) {
value ||= null
}
emit('update:modelValue', value)
emitFormInput()
}
Expand Down

0 comments on commit 9dd7e61

Please sign in to comment.