Skip to content

Commit

Permalink
coerce string and array empty values to null/None
Browse files Browse the repository at this point in the history
  • Loading branch information
ritch committed Jan 10, 2025
1 parent 7cc51ce commit a753508
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/packages/core/src/plugins/SchemaIO/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function SchemaIOComponent(props) {

const onIOChange = useCallback(
(path, value, schema, ancestors) => {
value = coerceValue(value, schema);
const currentState = stateRef.current;
const updatedState = cloneDeep(currentState);
set(updatedState, path, cloneDeep(value));
Expand Down Expand Up @@ -63,6 +64,17 @@ export function SchemaIOComponent(props) {
);
}

function coerceValue(value, schema) {
// coerce the value to None if it is an empty string or empty array
if (schema.type === "array" && Array.isArray(value) && value.length === 0) {
return null;
}
if (schema.type === "string" && value === "") {
return null;
}
return value;
}

registerComponent({
name: "SchemaIOComponent",
label: "SchemaIOComponent",
Expand Down

0 comments on commit a753508

Please sign in to comment.