You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This will render `<input id="root/first">` instead of `<input
440
440
id="root_first">` when rendering `first`.
441
441
442
+
## nameGenerator
443
+
444
+
The `nameGenerator` prop allows you to customize how HTML `name` attributes are generated for form fields. This is essential when submitting form data to backend frameworks that expect specific naming conventions for structured data.
445
+
446
+
**Default behavior:** When no `nameGenerator` is provided, the `name` attribute will equal the `id` attribute (e.g., `root_tasks_0_title`).
447
+
448
+
RJSF provides two built-in generators:
449
+
450
+
**`bracketNameGenerator`** - Generates bracket notation for PHP/Rails (e.g., `root[tasks][0][title]`). Automatically appends `[]` for multi-value fields like checkboxes.
451
+
452
+
**`dotNotationNameGenerator`** - Generates dot notation for other frameworks (e.g., `root.tasks.0.title`).
You can also create a custom generator by implementing the `NameGeneratorFunction` type, which receives `path` (array of path segments), `idPrefix` (typically `'root'`), and optional `isMultiValue` (boolean for multi-value fields).
482
+
442
483
## liveOmit
443
484
444
485
If `omitExtraData` and `liveOmit` are both set to true, then extra form data values that are not in any form field will be removed whenever `onChange` is called. Set to `false` by default.
/** Optional function to generate custom HTML name attributes for form elements. Receives the field path segments
382
+
* and element type (object or array), and returns a custom name string. This allows backends like PHP/Rails
383
+
* (`root[tasks][0][title]`) or Django (`root__tasks-0__title`) to receive form data in their expected format.
384
+
*/
385
+
readonly nameGenerator?:NameGeneratorFunction;
381
386
};
382
387
```
383
388
@@ -729,7 +734,7 @@ Many new or formerly internally private utility functions are available in `@rjs
729
734
-`optionalControlsId(id: FieldPathId | string, element: 'Add' | 'Msg' | 'Remove')`: Return a consistent `id` for the optional data controls `element`
730
735
-`shouldRenderOptionalField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>(registry: Registry<T, S, F>, schema: S, required: boolean, uiSchema?: UiSchema<T, S, F>): boolean`: Determines if this field should be rendered with the Optional Data Controls UI.
731
736
-`sortedJSONStringify(object: unknown): string`: Stringifies an `object`, sorts object fields in consistent order before stringifying it.
732
-
-`toFieldPathId(fieldPath: string | number, globalFormOptions: GlobalFormOptions, parentPath?: FieldPathId | FieldPathList)`: Constructs the `FieldPathId` for `fieldPath` and the optional `parentPath`, using `globalFormOptions`
737
+
-`toFieldPathId(fieldPath: string | number, globalFormOptions: GlobalFormOptions, parentPath?: FieldPathId | FieldPathList, isMultiValue?: boolean)`: Constructs the `FieldPathId` for `fieldPath` and the optional `parentPath`, using `globalFormOptions`
733
738
734
739
### New validator-based utility functions
735
740
@@ -773,3 +778,9 @@ const uiSchema: UiSchema = {
773
778
774
779
This feature is fully backward compatible - existing forms using object-based `uiSchema.items` will continue to work without changes.
775
780
See the [Dynamic UI Schema Examples](../api-reference/dynamic-ui-schema-examples.md) documentation for comprehensive examples and usage patterns.
781
+
782
+
### Custom field `name` generation
783
+
784
+
RJSF 6.x adds support for customizing how HTML `name` attributes are generated for form fields via the new [`nameGenerator`](../api-reference/form-props.md#namegenerator) prop. This enables proper form data submission to backend frameworks that expect specific naming conventions like bracket notation (`root[tasks][0][title]`) for PHP/Rails or dot notation (`root.tasks.0.title`) for other frameworks.
785
+
786
+
The default behavior is unchanged if the prop is not provided.
0 commit comments