Skip to content

Commit c05dbc1

Browse files
authored
Fixed issue where oneOf radio button could not be modified when defaults were set (#4644)
1 parent cce870f commit c05dbc1

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ should change the heading of the (upcoming) version to include a major version b
1616
1717
-->
1818

19+
# 6.0.0-beta.11
20+
21+
## @rjsf/utils
22+
23+
- Fixed issue where oneOf radio button could not be modified when defaults were set, fixing [#4634](https://github.com/rjsf-team/react-jsonschema-form/issues/4634)
24+
1925
# 6.0.0-beta.10
2026

2127
## @rjsf/mui
@@ -61,7 +67,7 @@ should change the heading of the (upcoming) version to include a major version b
6167

6268
- Updated the `README.md` file for dependencies
6369

64-
## @rjsf/util
70+
## @rjsf/utils
6571

6672
- Fixed form data propagation with `patternProperties` [#4617](https://github.com/rjsf-team/react-jsonschema-form/pull/4617)
6773
- Updated the `GlobalUISchemaOptions` types to extend `GenericObjectType` to support user-defined values for their extensions
@@ -83,7 +89,7 @@ should change the heading of the (upcoming) version to include a major version b
8389

8490
- Updated `LayoutGridField` to use the pre-existing `UI_GLOBAL_OPTIONS_KEY` instead of its own incorrect one.
8591

86-
## @rjsf/util
92+
## @rjsf/utils
8793

8894
- Fixed form data propagation with `patternProperties` [#4617](https://github.com/rjsf-team/react-jsonschema-form/pull/4617)
8995
- Fixed issue where oneOf schema references could not be modified when defaults were set, fixing [#4580](https://github.com/rjsf-team/react-jsonschema-form/issues/4580).
@@ -101,7 +107,7 @@ should change the heading of the (upcoming) version to include a major version b
101107

102108
# 6.0.0-beta.6
103109

104-
## @rjsf/util
110+
## @rjsf/utils
105111

106112
- Updated the `Field` type to add the optional `TEST_IDS?: TestIdShape` prop to it to support exposing the `TEST_IDS` static prop on `LayoutGridField`, `LayoutHeaderField` and `LayoutMultiSchemaField` for external users
107113

packages/core/test/Form.test.jsx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,83 @@ describeRepeated('Form common', (createFormComponent) => {
15471547

15481548
expect(node.querySelector(protocolInputID).value).to.equal('1');
15491549
});
1550+
it('Should modify oneOf radio button when the defaults are set.', () => {
1551+
const schema = {
1552+
type: 'object',
1553+
properties: {
1554+
a: {
1555+
type: ['boolean', 'null'],
1556+
default: null,
1557+
oneOf: [
1558+
{
1559+
const: false,
1560+
title: 'No',
1561+
},
1562+
{
1563+
const: null,
1564+
title: 'N/A',
1565+
},
1566+
],
1567+
},
1568+
},
1569+
allOf: [
1570+
{
1571+
if: {
1572+
required: ['a'],
1573+
properties: {
1574+
a: {
1575+
const: false,
1576+
},
1577+
},
1578+
},
1579+
then: {
1580+
required: ['b'],
1581+
properties: {
1582+
b: {
1583+
type: 'string',
1584+
},
1585+
},
1586+
},
1587+
},
1588+
],
1589+
};
1590+
1591+
const uiSchema = {
1592+
a: {
1593+
'ui:widget': 'radio',
1594+
'ui:label': false,
1595+
},
1596+
};
1597+
1598+
const { node, onChange } = createFormComponent({
1599+
schema,
1600+
uiSchema,
1601+
});
1602+
1603+
const notApplicableInputID = '#root_a-1';
1604+
const NoInputID = '#root_a-0';
1605+
expect(node.querySelector(notApplicableInputID).checked).to.equal(true);
1606+
1607+
act(() => {
1608+
fireEvent.click(node.querySelector(NoInputID));
1609+
});
1610+
1611+
sinon.assert.calledWithMatch(
1612+
onChange.lastCall,
1613+
{
1614+
formData: {
1615+
a: false,
1616+
},
1617+
schema,
1618+
uiSchema,
1619+
},
1620+
'root_a',
1621+
);
1622+
1623+
expect(node.querySelector(NoInputID).checked).to.equal(true);
1624+
expect(node.querySelector(notApplicableInputID).checked).to.equal(false);
1625+
expect(node.querySelector('#root_b')).to.exist;
1626+
});
15501627
});
15511628

15521629
describe('Blur handler', () => {

packages/utils/src/schema/getDefaultFormState.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema
213213
let experimental_dfsb_to_compute = experimental_defaultFormStateBehavior;
214214
let updatedRecurseList = _recurseList;
215215
if (
216-
schema[CONST_KEY] &&
216+
schema[CONST_KEY] !== undefined &&
217217
experimental_defaultFormStateBehavior?.constAsDefaults !== 'never' &&
218218
!constIsAjvDataReference(schema)
219219
) {

0 commit comments

Comments
 (0)