From 20ebb1a87affbc9e00976620090930126eee7d93 Mon Sep 17 00:00:00 2001 From: honzapatCZ Date: Tue, 25 Aug 2026 13:28:01 +0200 Subject: [PATCH] do not send empty data --- Parts/Input.tsx | 43 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 5 deletions(-) diff --git a/Parts/Input.tsx b/Parts/Input.tsx index d9d3151..4b9be9d 100644 --- a/Parts/Input.tsx +++ b/Parts/Input.tsx @@ -23,13 +23,23 @@ export default function Input( title?: string; children?: React.ReactNode; className?: string; + sendEmpty?: boolean; } ) { /*name, id*/ - let { children, ...otherProps } = props; + let { children, sendEmpty = false, ...otherProps } = props; const [field, meta, helpers] = useField(otherProps); + const handleChange = (e: React.ChangeEvent) => { + if (otherProps.onChange) { + otherProps.onChange(e); + return; + } + const val = (!sendEmpty && e.target.value === "") ? null : e.target.value; + field.onChange({ target: { value: val, name: field.name } }); + }; + return (
{props.title && ( @@ -46,6 +56,8 @@ export default function Input( @@ -65,10 +77,11 @@ export function MaskedInput( title?: string; children?: React.ReactNode; className?: string; + sendEmpty?: boolean; } ) { /*name, id*/ - let { children, validate, ...otherProps } = props; + let { children, validate, sendEmpty = false, ...otherProps } = props; const [field, meta, helpers] = useField({ ...otherProps, validate }); @@ -88,10 +101,13 @@ export function MaskedInput( field.onChange({ target: { value, name: field.name } }) + (value, mask) => { + const val = (!sendEmpty && value === "") ? null : value; + field.onChange({ target: { value: val, name: field.name } }); + } } onBlur={field.onBlur} tw="bg-primary appearance-none border-2 border-secondary rounded w-full py-2 px-4 text-primary leading-tight focus:outline-none focus:bg-secondary focus:border-accent transition duration-150 " @@ -108,11 +124,26 @@ export function TextArea({ title, children = null, label = null, + sendEmpty = false, ...props +}: { + title?: string; + children?: React.ReactNode; + label?: any; + sendEmpty?: boolean; + [key: string]: any; }) { - const [field, meta, helpers] = useField(props); + const handleChange = (e: React.ChangeEvent) => { + if (props.onChange) { + props.onChange(e); + return; + } + const val = (!sendEmpty && e.target.value === "") ? null : e.target.value; + field.onChange({ target: { value: val, name: field.name } }); + }; + return (
{title && ( @@ -127,6 +158,8 @@ export function TextArea({