Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Input/Textarea): nullify model modifier #2309

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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