From 215b60eadce0298673393a1f801b24feaa85dfb0 Mon Sep 17 00:00:00 2001 From: luizakp Date: Tue, 24 Sep 2024 15:04:56 -0300 Subject: [PATCH] chore: transform into bool before passing as switch value --- .../FormBuilder/fields/SwitchField.tsx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/components/FormBuilder/fields/SwitchField.tsx b/src/components/FormBuilder/fields/SwitchField.tsx index ba0bbaa..2713e1d 100644 --- a/src/components/FormBuilder/fields/SwitchField.tsx +++ b/src/components/FormBuilder/fields/SwitchField.tsx @@ -15,6 +15,22 @@ export interface SwitchFieldProps extends BaseField { type: "switch"; } +function transformIntoBoolean(value: any): boolean { + if (typeof value === "boolean") { + return value; + } + + if (typeof value === "string") { + return value === "true"; + } + + if (typeof value === "number") { + return value === 1; + } + + return false; +} + export const SwitchField = withConditional( ({ form, field }) => { const disabled = @@ -40,7 +56,7 @@ export const SwitchField = withConditional(