diff --git a/v0/package.json b/v0/package.json index fe62bde1..6d01e02c 100644 --- a/v0/package.json +++ b/v0/package.json @@ -82,4 +82,4 @@ "engines": { "node": ">=18.14.0" } -} \ No newline at end of file +} diff --git a/v0/src/helpers.js b/v0/src/helpers.js index 4373d44b..5b69baaa 100644 --- a/v0/src/helpers.js +++ b/v0/src/helpers.js @@ -579,7 +579,7 @@ export function extractParametersFromNode(schemaNode) { ...(presentation?.inputType === 'checkbox' && { checkboxValue: node.const }), // - For checkboxes with boolean value ...(presentation?.inputType === 'checkbox' && - node.type === 'boolean' && { + hasType(node.type, 'boolean') && { // true is what describes this checkbox as a boolean, regardless if its required or not checkboxValue: true, }), diff --git a/v0/src/tests/createHeadlessForm.test.js b/v0/src/tests/createHeadlessForm.test.js index 0472141d..0ee6de00 100644 --- a/v0/src/tests/createHeadlessForm.test.js +++ b/v0/src/tests/createHeadlessForm.test.js @@ -2327,6 +2327,28 @@ describe('createHeadlessForm', () => { // Explained at "Given values from hidden fields, it does not thrown an error" expect(handleValidation({ has_pet: false, pet_is_cat: true }).formErrors).toBeUndefined(); }); + + it('should set checkboxValue: true for optional boolean type', () => { + const schema = { + type: 'object', + properties: { + boolean_checkbox: { + title: 'Boolean Checkbox Test', + type: ['boolean', 'null'], + 'x-jsf-presentation': { + inputType: 'checkbox', + }, + }, + }, + required: [], + }; + + const result = createHeadlessForm(schema); + + const [optionalCheckbox] = result.fields; + expect(optionalCheckbox?.inputType).toBe('checkbox'); + expect(optionalCheckbox?.checkboxValue).toBe(true); + }); }); });