Skip to content

Commit c921892

Browse files
committed
feat: Add htmlName prop
1 parent 4747213 commit c921892

16 files changed

+56
-14
lines changed

packages/core/src/components/Form.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
DEFAULT_ID_SEPARATOR,
4444
DEFAULT_ID_PREFIX,
4545
GlobalFormOptions,
46+
NameGeneratorFunction,
4647
} from '@rjsf/utils';
4748
import _cloneDeep from 'lodash/cloneDeep';
4849
import _forEach from 'lodash/forEach';
@@ -198,6 +199,7 @@ export interface FormProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
198199
* to put the second parameter before the first in its translation.
199200
*/
200201
translateString?: Registry['translateString'];
202+
nameGenerator?: NameGeneratorFunction;
201203
/** Optional configuration object with flags, if provided, allows users to override default form state behavior
202204
* Currently only affecting minItems on array fields and handling of setting defaults based on the value of
203205
* `emptyObjectFields`
@@ -975,10 +977,16 @@ export default class Form<
975977
experimental_componentUpdateStrategy,
976978
idSeparator = DEFAULT_ID_SEPARATOR,
977979
idPrefix = DEFAULT_ID_PREFIX,
980+
nameGenerator,
978981
} = props;
979982
const rootFieldId = uiSchema['ui:rootFieldId'];
980983
// Omit any options that are undefined or null
981-
return { idPrefix: rootFieldId || idPrefix, idSeparator, experimental_componentUpdateStrategy };
984+
return {
985+
idPrefix: rootFieldId || idPrefix,
986+
idSeparator,
987+
...(experimental_componentUpdateStrategy !== undefined && { experimental_componentUpdateStrategy }),
988+
...(nameGenerator !== undefined && { nameGenerator }),
989+
};
982990
}
983991

984992
/** Returns the registry for the form */

packages/core/src/components/fields/ArrayField.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
616616
formContext={formContext}
617617
autofocus={autofocus}
618618
rawErrors={rawErrors}
619+
htmlName={fieldPathId.name}
619620
/>
620621
);
621622
}
@@ -668,6 +669,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
668669
formContext={formContext}
669670
autofocus={autofocus}
670671
rawErrors={rawErrors}
672+
htmlName={fieldPathId.name}
671673
/>
672674
);
673675
}
@@ -716,6 +718,7 @@ class ArrayField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends For
716718
rawErrors={rawErrors}
717719
label={label}
718720
hideLabel={!displayLabel}
721+
htmlName={fieldPathId.name}
719722
/>
720723
);
721724
}

packages/core/src/components/fields/BooleanField.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ function BooleanField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extend
117117
formContext={formContext}
118118
autofocus={autofocus}
119119
rawErrors={rawErrors}
120+
htmlName={fieldPathId.name}
120121
/>
121122
);
122123
}

packages/core/src/components/fields/LayoutMultiSchemaField.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ export default function LayoutMultiSchemaField<
222222
onFocus={onFocus}
223223
value={selectedOption}
224224
options={widgetOptions}
225+
htmlName={fieldPathId.name}
225226
/>
226227
</FieldTemplate>
227228
);

packages/core/src/components/fields/StringField.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function StringField<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
7575
registry={registry}
7676
placeholder={placeholder}
7777
rawErrors={rawErrors}
78+
htmlName={fieldPathId.name}
7879
/>
7980
);
8081
}

packages/core/src/components/templates/BaseInputTemplate.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default function BaseInputTemplate<
2323
const {
2424
id,
2525
name, // remove this from ...rest
26+
htmlName,
2627
value,
2728
readonly,
2829
disabled,
@@ -78,7 +79,7 @@ export default function BaseInputTemplate<
7879
<>
7980
<input
8081
id={id}
81-
name={id}
82+
name={htmlName || id}
8283
className='form-control'
8384
readOnly={readonly}
8485
disabled={disabled}

packages/core/src/components/widgets/CheckboxWidget.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
3131
onFocus,
3232
onChange,
3333
registry,
34+
htmlName,
3435
}: WidgetProps<T, S, F>) {
3536
const DescriptionFieldTemplate = getTemplate<'DescriptionFieldTemplate', T, S, F>(
3637
'DescriptionFieldTemplate',
@@ -73,7 +74,7 @@ function CheckboxWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F exte
7374
<input
7475
type='checkbox'
7576
id={id}
76-
name={id}
77+
name={htmlName || id}
7778
checked={typeof value === 'undefined' ? false : value}
7879
required={required}
7980
disabled={disabled || readonly}

packages/core/src/components/widgets/CheckboxesWidget.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
2727
onChange,
2828
onBlur,
2929
onFocus,
30+
htmlName,
3031
}: WidgetProps<T, S, F>) {
3132
const checkboxesValues = Array.isArray(value) ? value : [value];
3233

@@ -62,7 +63,7 @@ function CheckboxesWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F ex
6263
<input
6364
type='checkbox'
6465
id={optionId(id, index)}
65-
name={id}
66+
name={htmlName || id}
6667
checked={checked}
6768
value={String(index)}
6869
disabled={disabled || itemDisabled || readonly}

packages/core/src/components/widgets/HiddenWidget.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import { FormContextType, RJSFSchema, StrictRJSFSchema, WidgetProps } from '@rjs
88
function HiddenWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>({
99
id,
1010
value,
11+
htmlName,
1112
}: WidgetProps<T, S, F>) {
12-
return <input type='hidden' id={id} name={id} value={typeof value === 'undefined' ? '' : value} />;
13+
return <input type='hidden' id={id} name={htmlName || id} value={typeof value === 'undefined' ? '' : value} />;
1314
}
1415

1516
export default HiddenWidget;

packages/core/src/components/widgets/RadioWidget.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
2626
onFocus,
2727
onChange,
2828
id,
29+
htmlName,
2930
}: WidgetProps<T, S, F>) {
3031
const { enumOptions, enumDisabled, inline, emptyValue } = options;
3132

@@ -57,7 +58,7 @@ function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends
5758
type='radio'
5859
id={optionId(id, i)}
5960
checked={checked}
60-
name={id}
61+
name={htmlName || id}
6162
required={required}
6263
value={String(i)}
6364
disabled={disabled || itemDisabled || readonly}

0 commit comments

Comments
 (0)