Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion v0/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,4 @@
"engines": {
"node": ">=18.14.0"
}
}
}
2 changes: 1 addition & 1 deletion v0/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
Expand Down
22 changes: 22 additions & 0 deletions v0/src/tests/createHeadlessForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});

Expand Down