Skip to content

Commit e744e73

Browse files
fix(SelectWidget): use real enum values for option values when nameGenerator is active (#5004)
* fix(SelectWidget): use real enum values for option values when nameGenerator is active When htmlName is present (nameGenerator enabled), SelectWidget rendered option values as array indices (0, 1, 2) instead of real enum values (e.g. "active", "inactive"). This broke native form submission since the POSTed value was the index, not the actual value. Fixes all 10 themes. * fix(SelectWidget): render empty string for undefined values instead of undefined * fix(SelectWidget): streamline value handling for real and enumerated options * fix(SelectWidget): use real enum values in <option value> with data-index for typed resolution Replace index-based <option value="0"> with real enum values <option value="real_value"> so that native form submission sends meaningful values. Add data-index attribute to preserve typed value resolution via enumOptionsValueForIndex in JS handlers. Scope limited to core and react-bootstrap (native <select> packages). Custom component packages (chakra, mui, mantine, etc.) are unchanged as they don't participate in native form submission. * feat(widgets): add opt-in useRealOptionValues for native form submission Add enumOptionValueEncoder/Decoder utilities to @rjsf/utils that allow rendering real enum values in option attributes instead of array indices. Controlled via ui:globalOptions or per-field ui:options. When enabled, primitives use String(value) for DOM attributes with reverse lookup decoding. Objects/arrays fall back to index encoding. Default behavior (index-based) is fully preserved. Applied across SelectWidget, RadioWidget, and CheckboxesWidget in all 10 theme packages. * fix(SelectWidget, RadioWidget): ensure enum option values are converted to strings before processing * Update packages/utils/src/enumOptionValueDecoder.ts Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com> * Update packages/utils/test/enumOptionValueDecoder.test.ts Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com> * Update packages/utils/test/enumOptionValueEncoder.test.ts Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com> * fix(enumOptionValueDecoder): add test for handling undefined enumOptions * feat(SelectWidget, utils): implement real enum value rendering and add new utilities for select options * fix: Update snapshots * feat(antd): add opt-in useRealOptionValues support * feat(utils): rename useRealOptionValues to optionValueFormat Replace the boolean flag with a 'indexed' | 'realValue' union on GlobalUISchemaOptions for consistency with other option-style APIs in RJSF. Add an OptionValueFormat type and update the encoder, decoder, and selectedValue utilities to take a format parameter that defaults to 'indexed'. * docs(uiSchema): add optionValueFormat section to describe enum value encoding * refactor(utils): add getOptionValueFormat resolver helper * refactor(chakra-ui,mui): use enumOptionSelectedValue in Radio/Checkboxes * refactor(chakra-ui): unify SelectWidget formValue via enumOptionSelectedValue * refactor(select-widget): comment about flatten `formValue` structure for Chakra and DaisyUI SelectWidgets * refactor(mantine): split SelectWidget into Select/MultiSelect branches Replace the `Component = multiple ? MultiSelect : Select` pattern with two explicit JSX branches sharing a common props object. Each branch passes its own narrow value type (`string[]` for MultiSelect, `string | null` for Select), dropping both the `as any` cast and the `multiple ? [] : null` conditional on enumOptionSelectedValue's emptyValue argument. * refactor: address second-round review comments --------- Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
1 parent f192d62 commit e744e73

45 files changed

Lines changed: 935 additions & 351 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ should change the heading of the (upcoming) version to include a major version b
2828
## @rjsf/chakra-ui
2929

3030
- Added `key={label}` to key input in `WrapIfAdditionalTemplate` to reset input value after duplicate key rename ([#4999](https://github.com/rjsf-team/react-jsonschema-form/issues/4999))
31+
- Added opt-in `optionValueFormat: 'realValue'` support to `SelectWidget`, `RadioWidget`, and `CheckboxesWidget` ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
3132

3233
## @rjsf/core
3334

@@ -36,39 +37,48 @@ should change the heading of the (upcoming) version to include a major version b
3637
- Fixed focus being lost when renaming additional property keys by preserving React key for renamed properties ([#4999](https://github.com/rjsf-team/react-jsonschema-form/issues/4999))
3738
- Removed `expandUiSchemaDefinitions` call at form init, now handled at runtime by `resolveUiSchema`, fixing [#4986](https://github.com/rjsf-team/react-jsonschema-form/issues/4986)
3839
- Used `useRef` to track latest `formData` in `handleKeyRename`, preventing stale closure data when multiple additional property keys are renamed in quick succession, fixing [#5021](https://github.com/rjsf-team/react-jsonschema-form/issues/5021)
40+
- Added opt-in `optionValueFormat: 'realValue'` support to `SelectWidget`, `RadioWidget`, and `CheckboxesWidget` for rendering real enum values in DOM attributes instead of array indices ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
3941

4042
## @rjsf/daisyui
4143

4244
- Added `key={label}` to key input in `WrapIfAdditionalTemplate` to reset input value after duplicate key rename ([#4999](https://github.com/rjsf-team/react-jsonschema-form/issues/4999))
45+
- Added opt-in `optionValueFormat: 'realValue'` support to `SelectWidget`, `RadioWidget`, and `CheckboxesWidget` ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
4346

4447
## @rjsf/fluentui-rc
4548

4649
- Added `key={label}` to key input in `WrapIfAdditionalTemplate` to reset input value after duplicate key rename ([#4999](https://github.com/rjsf-team/react-jsonschema-form/issues/4999))
50+
- Added opt-in `optionValueFormat: 'realValue'` support to `SelectWidget`, `RadioWidget`, and `CheckboxesWidget` ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
4751

4852
## @rjsf/mantine
4953

5054
- Added `key={label}` to key input in `WrapIfAdditionalTemplate` to reset input value after duplicate key rename ([#4999](https://github.com/rjsf-team/react-jsonschema-form/issues/4999))
5155
- Updated `BaseInputTemplate` to destructure and guard `min`/`max` before spreading onto `NumberInput`, fixing a build error caused by the widened `InputPropsType` (`number | string`)
56+
- Added opt-in `optionValueFormat: 'realValue'` support to `SelectWidget`, `RadioWidget`, and `CheckboxesWidget` ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
5257

5358
## @rjsf/mui
5459

5560
- Added `key={label}` to key input in `WrapIfAdditionalTemplate` to reset input value after duplicate key rename ([#4999](https://github.com/rjsf-team/react-jsonschema-form/issues/4999))
61+
- Added opt-in `optionValueFormat: 'realValue'` support to `SelectWidget`, `RadioWidget`, and `CheckboxesWidget` ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
5662

5763
## @rjsf/primereact
5864

5965
- Added `key={label}` to key input in `WrapIfAdditionalTemplate` to reset input value after duplicate key rename ([#4999](https://github.com/rjsf-team/react-jsonschema-form/issues/4999))
66+
- Added opt-in `optionValueFormat: 'realValue'` support to `SelectWidget`, `RadioWidget`, and `CheckboxesWidget` ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
6067

6168
## @rjsf/react-bootstrap
6269

6370
- Added `key={label}` to key input in `WrapIfAdditionalTemplate` to reset input value after duplicate key rename ([#4999](https://github.com/rjsf-team/react-jsonschema-form/issues/4999))
71+
- Added opt-in `optionValueFormat: 'realValue'` support to `SelectWidget`, `RadioWidget`, and `CheckboxesWidget` ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
6472

6573
## @rjsf/semantic-ui
6674

6775
- Added `key={label}` to key input in `WrapIfAdditionalTemplate` to reset input value after duplicate key rename ([#4999](https://github.com/rjsf-team/react-jsonschema-form/issues/4999))
76+
- Added opt-in `optionValueFormat: 'realValue'` support to `SelectWidget`, `RadioWidget`, and `CheckboxesWidget` ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
6877

6978
## @rjsf/shadcn
7079

7180
- Added `key={label}` to key input in `WrapIfAdditionalTemplate` to reset input value after duplicate key rename ([#4999](https://github.com/rjsf-team/react-jsonschema-form/issues/4999))
81+
- Added opt-in `optionValueFormat: 'realValue'` support to `SelectWidget`, `RadioWidget`, and `CheckboxesWidget` ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
7282

7383
## @rjsf/mui
7484

@@ -80,6 +90,8 @@ should change the heading of the (upcoming) version to include a major version b
8090
- Updated `InputPropsType` to widen `min` and `max` to `number | string` to support date values (e.g. `"2020-01-01"`)
8191
- Updated `getInputProps()` to propagate `formatMinimum` and `formatMaximum` schema keywords to the HTML `min`/`max` attributes for `date`, `datetime-local`, `time`, `week`, and `month` input types, aligning browser-native date picker constraints with AJV validation
8292
- Fixed `ui:title` from `ui:definitions` not applied to `oneOf`/`anyOf` dropdowns beyond first recursion level, fixing [#4986](https://github.com/rjsf-team/react-jsonschema-form/issues/4986)
93+
- Added `enumOptionValueEncoder`, `enumOptionValueDecoder`, and `enumOptionSelectedValue` utilities for opt-in real enum value rendering in select/radio/checkbox widgets ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
94+
- Added `optionValueFormat: 'indexed' | 'realValue'` to `GlobalUISchemaOptions` and the `OptionValueFormat` type for opt-in real enum values in widget DOM attributes ([#4693](https://github.com/rjsf-team/react-jsonschema-form/issues/4693))
8395

8496
# @rjsf/validator-ajv8
8597

packages/antd/src/widgets/CheckboxesWidget/index.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { FocusEvent } from 'react';
22
import { Checkbox } from 'antd';
33
import {
44
ariaDescribedByIds,
5-
enumOptionsIndexForValue,
6-
enumOptionsValueForIndex,
5+
enumOptionSelectedValue,
6+
enumOptionValueDecoder,
7+
enumOptionValueEncoder,
8+
getOptionValueFormat,
79
optionId,
810
FormContextType,
911
WidgetProps,
@@ -38,14 +40,16 @@ export default function CheckboxesWidget<
3840
const { readonlyAsDisabled = true } = formContext as GenericObjectType;
3941

4042
const { enumOptions, enumDisabled, inline, emptyValue } = options;
43+
const optionValueFormat = getOptionValueFormat(options);
4144

42-
const handleChange = (nextValue: any) => onChange(enumOptionsValueForIndex<S>(nextValue, enumOptions, emptyValue));
45+
const handleChange = (nextValue: any) =>
46+
onChange(enumOptionValueDecoder<S>(nextValue, enumOptions, optionValueFormat, emptyValue));
4347

4448
const handleBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
45-
onBlur(id, enumOptionsValueForIndex<S>(target.value, enumOptions, emptyValue));
49+
onBlur(id, enumOptionValueDecoder<S>(target.value, enumOptions, optionValueFormat, emptyValue));
4650

4751
const handleFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
48-
onFocus(id, enumOptionsValueForIndex<S>(target.value, enumOptions, emptyValue));
52+
onFocus(id, enumOptionValueDecoder<S>(target.value, enumOptions, optionValueFormat, emptyValue));
4953

5054
// Antd's typescript definitions do not contain the following props that are actually necessary and, if provided,
5155
// they are used, so hacking them in via by spreading `extraProps` on the component to avoid typescript errors
@@ -55,15 +59,15 @@ export default function CheckboxesWidget<
5559
onFocus: !readonly ? handleFocus : undefined,
5660
};
5761

58-
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, true) as string[];
62+
const selectValue = enumOptionSelectedValue<S>(value, enumOptions, true, optionValueFormat, []) as string[];
5963

6064
return Array.isArray(enumOptions) && enumOptions.length > 0 ? (
6165
<>
6266
<Checkbox.Group
6367
disabled={disabled || (readonlyAsDisabled && readonly)}
6468
name={htmlName || id}
6569
onChange={!readonly ? handleChange : undefined}
66-
value={selectedIndexes}
70+
value={selectValue}
6771
{...extraProps}
6872
aria-describedby={ariaDescribedByIds(id)}
6973
>
@@ -75,7 +79,7 @@ export default function CheckboxesWidget<
7579
name={htmlName || id}
7680
autoFocus={i === 0 ? autofocus : false}
7781
disabled={Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1}
78-
value={String(i)}
82+
value={enumOptionValueEncoder(option.value, i, optionValueFormat)}
7983
>
8084
{option.label}
8185
</Checkbox>

packages/antd/src/widgets/RadioWidget/index.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { FocusEvent } from 'react';
22
import { Radio, RadioChangeEvent } from 'antd';
33
import {
44
ariaDescribedByIds,
5-
enumOptionsIndexForValue,
6-
enumOptionsValueForIndex,
5+
enumOptionSelectedValue,
6+
enumOptionValueDecoder,
7+
enumOptionValueEncoder,
8+
getOptionValueFormat,
79
optionId,
810
FormContextType,
911
GenericObjectType,
@@ -34,17 +36,18 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
3436
const { readonlyAsDisabled = true } = formContext as GenericObjectType;
3537

3638
const { enumOptions, enumDisabled, emptyValue } = options;
39+
const optionValueFormat = getOptionValueFormat(options);
3740

3841
const handleChange = ({ target: { value: nextValue } }: RadioChangeEvent) =>
39-
onChange(enumOptionsValueForIndex<S>(nextValue, enumOptions, emptyValue));
42+
onChange(enumOptionValueDecoder<S>(nextValue, enumOptions, optionValueFormat, emptyValue));
4043

4144
const handleBlur = ({ target }: FocusEvent<HTMLInputElement>) =>
42-
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
45+
onBlur(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
4346

4447
const handleFocus = ({ target }: FocusEvent<HTMLInputElement>) =>
45-
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
48+
onFocus(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
4649

47-
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions) as string;
50+
const selectValue = enumOptionSelectedValue<S>(value, enumOptions, false, optionValueFormat, emptyValue);
4851

4952
return (
5053
<Radio.Group
@@ -54,7 +57,7 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
5457
onChange={!readonly ? handleChange : undefined}
5558
onBlur={!readonly ? handleBlur : undefined}
5659
onFocus={!readonly ? handleFocus : undefined}
57-
value={selectedIndexes}
60+
value={selectValue}
5861
aria-describedby={ariaDescribedByIds(id)}
5962
>
6063
{Array.isArray(enumOptions) &&
@@ -65,7 +68,7 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
6568
autoFocus={i === 0 ? autofocus : false}
6669
disabled={disabled || (Array.isArray(enumDisabled) && enumDisabled.indexOf(option.value) !== -1)}
6770
key={i}
68-
value={String(i)}
71+
value={enumOptionValueEncoder(option.value, i, optionValueFormat)}
6972
>
7073
{option.label}
7174
</Radio>

packages/antd/src/widgets/SelectWidget/index.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { useMemo, useState } from 'react';
22
import { Select, SelectProps } from 'antd';
33
import {
44
ariaDescribedByIds,
5-
enumOptionsIndexForValue,
6-
enumOptionsValueForIndex,
5+
enumOptionSelectedValue,
6+
enumOptionValueDecoder,
7+
enumOptionValueEncoder,
8+
getOptionValueFormat,
79
FormContextType,
810
GenericObjectType,
911
RJSFSchema,
@@ -47,12 +49,14 @@ export default function SelectWidget<
4749
const { readonlyAsDisabled = true } = formContext as GenericObjectType;
4850

4951
const { enumOptions, enumDisabled, emptyValue } = options;
52+
const optionValueFormat = getOptionValueFormat(options);
5053

51-
const handleChange = (nextValue: any) => onChange(enumOptionsValueForIndex<S>(nextValue, enumOptions, emptyValue));
54+
const handleChange = (nextValue: any) =>
55+
onChange(enumOptionValueDecoder<S>(nextValue, enumOptions, optionValueFormat, emptyValue));
5256

53-
const handleBlur = () => onBlur(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
57+
const handleBlur = () => onBlur(id, enumOptionValueDecoder<S>(value, enumOptions, optionValueFormat, emptyValue));
5458

55-
const handleFocus = () => onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
59+
const handleFocus = () => onFocus(id, enumOptionValueDecoder<S>(value, enumOptions, optionValueFormat, emptyValue));
5660

5761
const filterOption: SelectProps['filterOption'] = (input, option) => {
5862
if (option && isString(option.label)) {
@@ -64,7 +68,7 @@ export default function SelectWidget<
6468

6569
const getPopupContainer = SelectWidget.getPopupContainerCallback();
6670

67-
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, multiple);
71+
const selectValue = enumOptionSelectedValue<S>(value, enumOptions, !!multiple, optionValueFormat, emptyValue);
6872

6973
// Antd's typescript definitions do not contain the following props that are actually necessary and, if provided,
7074
// they are used, so hacking them in via by spreading `extraProps` on the component to avoid typescript errors
@@ -79,7 +83,7 @@ export default function SelectWidget<
7983
const options: DefaultOptionType[] = enumOptions.map(({ value: optionValue, label: optionLabel }, index) => ({
8084
disabled: Array.isArray(enumDisabled) && enumDisabled.indexOf(optionValue) !== -1,
8185
key: String(index),
82-
value: String(index),
86+
value: enumOptionValueEncoder(optionValue, index, optionValueFormat),
8387
label: optionLabel,
8488
}));
8589

@@ -89,7 +93,7 @@ export default function SelectWidget<
8993
return options;
9094
}
9195
return undefined;
92-
}, [enumDisabled, enumOptions, placeholder, showPlaceholderOption]);
96+
}, [enumDisabled, enumOptions, placeholder, showPlaceholderOption, optionValueFormat]);
9397

9498
return (
9599
<Select
@@ -104,7 +108,7 @@ export default function SelectWidget<
104108
onFocus={!readonly ? handleFocus : undefined}
105109
placeholder={placeholder}
106110
style={SELECT_STYLE}
107-
value={selectedIndexes}
111+
value={selectValue}
108112
{...extraProps}
109113
// When the open change is called, set the open state, needed so that the select opens properly in the playground
110114
onOpenChange={setOpen}

packages/chakra-ui/src/CheckboxesWidget/CheckboxesWidget.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { CheckboxGroup, FieldsetRoot, Stack, Text, FieldsetLegend } from '@chakra-ui/react';
22
import {
33
ariaDescribedByIds,
4-
enumOptionsIndexForValue,
5-
enumOptionsValueForIndex,
4+
enumOptionSelectedValue,
5+
enumOptionValueDecoder,
6+
enumOptionValueEncoder,
7+
getOptionValueFormat,
68
FormContextType,
79
optionId,
810
RJSFSchema,
@@ -37,14 +39,15 @@ export default function CheckboxesWidget<
3739
uiSchema,
3840
} = props;
3941
const { enumOptions, enumDisabled, emptyValue } = options;
42+
const optionValueFormat = getOptionValueFormat(options);
4043

4144
const _onBlur = ({ target }: FocusEvent<HTMLInputElement | any>) =>
42-
onBlur(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
45+
onBlur(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
4346
const _onFocus = ({ target }: FocusEvent<HTMLInputElement | any>) =>
44-
onFocus(id, enumOptionsValueForIndex<S>(target && target.value, enumOptions, emptyValue));
47+
onFocus(id, enumOptionValueDecoder<S>(target && target.value, enumOptions, optionValueFormat, emptyValue));
4548

4649
const row = options ? options.inline : false;
47-
const selectedIndexes = enumOptionsIndexForValue<S>(value, enumOptions, true) as string[];
50+
const selectValue = enumOptionSelectedValue<S>(value, enumOptions, true, optionValueFormat, []) as string[];
4851

4952
const chakraProps = getChakra({ uiSchema });
5053

@@ -57,8 +60,10 @@ export default function CheckboxesWidget<
5760
>
5861
{!hideLabel && label && <FieldsetLegend>{labelValue(label)}</FieldsetLegend>}
5962
<CheckboxGroup
60-
onValueChange={(option) => onChange(enumOptionsValueForIndex<S>(option, enumOptions, emptyValue))}
61-
value={selectedIndexes}
63+
onValueChange={(option) =>
64+
onChange(enumOptionValueDecoder<S>(option, enumOptions, optionValueFormat, emptyValue))
65+
}
66+
value={selectValue}
6267
aria-describedby={ariaDescribedByIds(id)}
6368
readOnly={readonly}
6469
invalid={required && value.length === 0}
@@ -72,7 +77,7 @@ export default function CheckboxesWidget<
7277
key={index}
7378
id={optionId(id, index)}
7479
name={htmlName || id}
75-
value={String(index)}
80+
value={enumOptionValueEncoder(option.value, index, optionValueFormat)}
7681
disabled={disabled || itemDisabled || readonly}
7782
onBlur={_onBlur}
7883
onFocus={_onFocus}

packages/chakra-ui/src/RadioWidget/RadioWidget.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import { ChangeEvent, FocusEvent } from 'react';
22
import { Stack } from '@chakra-ui/react';
33
import {
44
ariaDescribedByIds,
5-
enumOptionsIndexForValue,
6-
enumOptionsValueForIndex,
5+
enumOptionSelectedValue,
6+
enumOptionValueDecoder,
7+
enumOptionValueEncoder,
8+
getOptionValueFormat,
79
labelValue,
810
optionId,
911
FormContextType,
@@ -32,16 +34,17 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
3234
uiSchema,
3335
}: WidgetProps<T, S, F>) {
3436
const { enumOptions, enumDisabled, emptyValue } = options;
37+
const optionValueFormat = getOptionValueFormat(options);
3538

3639
const _onChange = ({ target: { value } }: ChangeEvent<HTMLInputElement>) =>
37-
onChange(enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
40+
onChange(enumOptionValueDecoder<S>(value, enumOptions, optionValueFormat, emptyValue));
3841
const _onBlur = ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
39-
onBlur(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
42+
onBlur(id, enumOptionValueDecoder<S>(value, enumOptions, optionValueFormat, emptyValue));
4043
const _onFocus = ({ target: { value } }: FocusEvent<HTMLInputElement>) =>
41-
onFocus(id, enumOptionsValueForIndex<S>(value, enumOptions, emptyValue));
44+
onFocus(id, enumOptionValueDecoder<S>(value, enumOptions, optionValueFormat, emptyValue));
4245

4346
const row = options ? options.inline : false;
44-
const selectedIndex = (enumOptionsIndexForValue<S>(value, enumOptions) as string) ?? null;
47+
const selectValue = enumOptionSelectedValue<S>(value, enumOptions, false, optionValueFormat, null);
4548

4649
const chakraProps = getChakra({ uiSchema });
4750

@@ -58,7 +61,7 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
5861
onChange={_onChange}
5962
onBlur={_onBlur}
6063
onFocus={_onFocus}
61-
value={selectedIndex}
64+
value={selectValue}
6265
name={htmlName || id}
6366
aria-describedby={ariaDescribedByIds(id)}
6467
>
@@ -69,7 +72,7 @@ export default function RadioWidget<T = any, S extends StrictRJSFSchema = RJSFSc
6972

7073
return (
7174
<Radio
72-
value={String(index)}
75+
value={enumOptionValueEncoder(option.value, index, optionValueFormat)}
7376
key={index}
7477
id={optionId(id, index)}
7578
disabled={disabled || itemDisabled || readonly}

0 commit comments

Comments
 (0)