@rjsf/utils
Version:
Utility functions for @rjsf/core
15 lines (14 loc) • 1.3 kB
TypeScript
import { FieldPathId, FieldPathList, GlobalFormOptions } from './types.js';
/** Constructs the `FieldPathId` for `fieldPath`. If `parentPathId` is provided, the `fieldPath` is appended to the end
* of the parent path. Then the `ID_KEY` of the resulting `FieldPathId` is constructed from the `idPrefix` and
* `idSeparator` contained within the `globalFormOptions`. If `fieldPath` is passed as an empty string, it will simply
* generate the path from the `parentPath` (if provided) and the `idPrefix` and `idSeparator`. If a `nameGenerator`
* is provided in `globalFormOptions`, it will also generate the HTML `name` attribute.
*
* @param fieldPath - The property name or array index of the current field element
* @param globalFormOptions - The `GlobalFormOptions` used to get the `idPrefix` and `idSeparator`
* @param [parentPath] - The optional `FieldPathId` or `FieldPathList` of the parent element for this field element
* @param [isMultiValue] - Optional flag indicating this field accepts multiple values
* @returns - The `FieldPathId` for the given `fieldPath` and the optional `parentPathId`
*/
export default function toFieldPathId(fieldPath: string | number, globalFormOptions: GlobalFormOptions, parentPath?: FieldPathId | FieldPathList, isMultiValue?: boolean): FieldPathId;