UNPKG

@rjsf/utils

Version:
20 lines (19 loc) 1.42 kB
import type { FormContextType, RJSFSchema, StrictRJSFSchema, ValidatorType } from './types.js'; /** Recursively removes optional objects from the `formData` that are empty (i.e., all their fields * are undefined, null, empty strings, or themselves empty optional objects). This solves the problem * where interacting with fields inside an optional object "activates" it permanently, making the * form unsubmittable when the optional object has required inner fields. * * An object property is considered "optional" when it is NOT listed in its parent schema's `required` * array. * * @param validator - An implementation of the `ValidatorType` interface that will be used when necessary * @param schema - The JSON schema describing the `formData` * @param [rootSchema] - The root schema, used primarily to look up `$ref`s * @param [formData] - The current form data to prune * @returns - A new copy of `formData` with empty optional objects removed, or `undefined` if the * entire formData was pruned * @deprecated - This function will be removed in a future release. The equivalent pruning behavior * is now built into `omitExtraData` — use that instead. */ export default function removeOptionalEmptyObjects<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(validator: ValidatorType<T, S, F>, schema: S, rootSchema?: S, formData?: T): T | undefined;