fix validation for schema objects that can be null

This commit is contained in:
Josh Hawkins
2026-02-27 09:37:57 -06:00
parent 55c6c50c97
commit f7cc87e8ce
4 changed files with 78 additions and 13 deletions
@@ -16,6 +16,10 @@ export function TextWidget(props: WidgetProps) {
options,
} = props;
const isNullable = Array.isArray(schema.type)
? schema.type.includes("null")
: false;
return (
<Input
id={id}
@@ -24,7 +28,13 @@ export function TextWidget(props: WidgetProps) {
disabled={disabled || readonly}
placeholder={placeholder || (options.placeholder as string) || ""}
onChange={(e) =>
onChange(e.target.value === "" ? undefined : e.target.value)
onChange(
e.target.value === ""
? isNullable
? null
: undefined
: e.target.value,
)
}
onBlur={(e) => onBlur(id, e.target.value)}
onFocus={(e) => onFocus(id, e.target.value)}
@@ -16,6 +16,10 @@ export function TextareaWidget(props: WidgetProps) {
options,
} = props;
const isNullable = Array.isArray(schema.type)
? schema.type.includes("null")
: false;
return (
<Textarea
id={id}
@@ -24,7 +28,13 @@ export function TextareaWidget(props: WidgetProps) {
placeholder={placeholder || (options.placeholder as string) || ""}
rows={(options.rows as number) || 3}
onChange={(e) =>
onChange(e.target.value === "" ? undefined : e.target.value)
onChange(
e.target.value === ""
? isNullable
? null
: undefined
: e.target.value,
)
}
onBlur={(e) => onBlur(id, e.target.value)}
onFocus={(e) => onFocus(id, e.target.value)}