From d44de14e1928e7e5c3fc55843de7d3a024f07af5 Mon Sep 17 00:00:00 2001 From: Olly Dutton Date: Thu, 2 Oct 2025 09:13:16 +1000 Subject: [PATCH] fix(checkbox): Support optional boolean type --- src/field/schema.ts | 2 +- test/fields.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/field/schema.ts b/src/field/schema.ts index 60c394d3..e2686831 100644 --- a/src/field/schema.ts +++ b/src/field/schema.ts @@ -15,7 +15,7 @@ function addCheckboxAttributes(inputType: string, field: Field, schema: NonBoole field.checkboxValue = schema.const // However, if the schema type is boolean, we should set the valid value as `true` - if (schema.type === 'boolean') { + if (Array.isArray(schema.type) ? schema.type.includes('boolean') : schema.type === 'boolean') { field.checkboxValue = true } } diff --git a/test/fields.test.ts b/test/fields.test.ts index d39165d3..35f1d914 100644 --- a/test/fields.test.ts +++ b/test/fields.test.ts @@ -686,6 +686,18 @@ describe('fields', () => { expect(field?.checkboxValue).toBe(true) }) + it('uses checkbox input for boolean/null type array with boolean const value', () => { + const booleanNullSchema = { + 'x-jsf-presentation': { + inputType: 'checkbox' as const, + }, + 'type': ['boolean', 'null'], + } + const field = buildFieldSchema(booleanNullSchema, 'test') + expect(field?.inputType).toBe('checkbox') + expect(field?.checkboxValue).toBe(true) + }) + // Skipping these tests until we have group-array support describe('array type inputs', () => { it('uses group-array when items has properties', () => {