Skip to content

Commit 76e8927

Browse files
authored
fix(checkbox): Support optional boolean type for v0 (#236)
* fix(checkbox): Support optional boolean type for v0
1 parent 3d6ef16 commit 76e8927

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

v0/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@
8282
"engines": {
8383
"node": ">=18.14.0"
8484
}
85-
}
85+
}

v0/src/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ export function extractParametersFromNode(schemaNode) {
579579
...(presentation?.inputType === 'checkbox' && { checkboxValue: node.const }),
580580
// - For checkboxes with boolean value
581581
...(presentation?.inputType === 'checkbox' &&
582-
node.type === 'boolean' && {
582+
hasType(node.type, 'boolean') && {
583583
// true is what describes this checkbox as a boolean, regardless if its required or not
584584
checkboxValue: true,
585585
}),

v0/src/tests/createHeadlessForm.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,28 @@ describe('createHeadlessForm', () => {
23272327
// Explained at "Given values from hidden fields, it does not thrown an error"
23282328
expect(handleValidation({ has_pet: false, pet_is_cat: true }).formErrors).toBeUndefined();
23292329
});
2330+
2331+
it('should set checkboxValue: true for optional boolean type', () => {
2332+
const schema = {
2333+
type: 'object',
2334+
properties: {
2335+
boolean_checkbox: {
2336+
title: 'Boolean Checkbox Test',
2337+
type: ['boolean', 'null'],
2338+
'x-jsf-presentation': {
2339+
inputType: 'checkbox',
2340+
},
2341+
},
2342+
},
2343+
required: [],
2344+
};
2345+
2346+
const result = createHeadlessForm(schema);
2347+
2348+
const [optionalCheckbox] = result.fields;
2349+
expect(optionalCheckbox?.inputType).toBe('checkbox');
2350+
expect(optionalCheckbox?.checkboxValue).toBe(true);
2351+
});
23302352
});
23312353
});
23322354

0 commit comments

Comments
 (0)