Skip to content

Commit 1c3d73e

Browse files
authored
fix(checkbox): Support optional boolean type (#234)
1 parent e822903 commit 1c3d73e

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/field/schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function addCheckboxAttributes(inputType: string, field: Field, schema: NonBoole
1515
field.checkboxValue = schema.const
1616

1717
// However, if the schema type is boolean, we should set the valid value as `true`
18-
if (schema.type === 'boolean') {
18+
if (Array.isArray(schema.type) ? schema.type.includes('boolean') : schema.type === 'boolean') {
1919
field.checkboxValue = true
2020
}
2121
}

test/fields.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,18 @@ describe('fields', () => {
686686
expect(field?.checkboxValue).toBe(true)
687687
})
688688

689+
it('uses checkbox input for boolean/null type array with boolean const value', () => {
690+
const booleanNullSchema = {
691+
'x-jsf-presentation': {
692+
inputType: 'checkbox' as const,
693+
},
694+
'type': ['boolean', 'null'],
695+
}
696+
const field = buildFieldSchema(booleanNullSchema, 'test')
697+
expect(field?.inputType).toBe('checkbox')
698+
expect(field?.checkboxValue).toBe(true)
699+
})
700+
689701
// Skipping these tests until we have group-array support
690702
describe('array type inputs', () => {
691703
it('uses group-array when items has properties', () => {

0 commit comments

Comments
 (0)