Skip to content

Commit 3844c48

Browse files
committed
feat: Add idPrefix arg to nameGeneratorFunction
1 parent 621a1fa commit 3844c48

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

packages/utils/src/toFieldPathId.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ export default function toFieldPathId(
2424
// Generate name attribute if nameGenerator is provided
2525
let name: string | undefined;
2626
if (globalFormOptions.nameGenerator && path.length > 0) {
27-
// Determine element type based on the last element in the path
28-
const lastPathElement = path[path.length - 1];
29-
const elementType = typeof lastPathElement === 'number' ? 'array' : 'object';
30-
name = globalFormOptions.nameGenerator(path, elementType);
27+
name = globalFormOptions.nameGenerator(path, globalFormOptions.idPrefix);
3128
}
3229

3330
return { path, [ID_KEY]: id, ...(name !== undefined && { name }) };

packages/utils/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type FormContextType = GenericObjectType;
3636
export type TestIdShape = Record<string, string>;
3737

3838
/** Function to generate HTML name attributes from path segments */
39-
export type NameGeneratorFunction = (path: FieldPathList, elementType: 'object' | 'array') => string;
39+
export type NameGeneratorFunction = (path: FieldPathList, idPrefix: string) => string;
4040

4141
/** Experimental feature that specifies the Array `minItems` default form state behavior
4242
*/

0 commit comments

Comments
 (0)