From c33741a5e9599a0e7b944dc96baf57aeaf70ad12 Mon Sep 17 00:00:00 2001 From: Alan Bustamante Date: Fri, 1 Aug 2025 04:34:46 +0200 Subject: [PATCH] fix: improve boolean field handling in plugin configuration forms (#23160) Co-authored-by: crazywoola <427733928@qq.com> --- .../plugin-detail-panel/endpoint-modal.tsx | 17 ++++++++++++++++- .../components/tools/utils/to-form-schema.ts | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx b/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx index 130773e0c2..a715237a43 100644 --- a/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx +++ b/web/app/components/plugins/plugin-detail-panel/endpoint-modal.tsx @@ -47,7 +47,22 @@ const EndpointModal: FC = ({ return } } - onSaved(tempCredential) + + // Fix: Process boolean fields to ensure they are sent as proper boolean values + const processedCredential = { ...tempCredential } + formSchemas.forEach((field) => { + if (field.type === 'boolean' && processedCredential[field.name] !== undefined) { + const value = processedCredential[field.name] + if (typeof value === 'string') + processedCredential[field.name] = value === 'true' || value === '1' || value === 'True' + else if (typeof value === 'number') + processedCredential[field.name] = value === 1 + else if (typeof value === 'boolean') + processedCredential[field.name] = value + } + }) + + onSaved(processedCredential) } return ( diff --git a/web/app/components/tools/utils/to-form-schema.ts b/web/app/components/tools/utils/to-form-schema.ts index ee7f3379ad..ae43e6f157 100644 --- a/web/app/components/tools/utils/to-form-schema.ts +++ b/web/app/components/tools/utils/to-form-schema.ts @@ -63,6 +63,16 @@ export const addDefaultValue = (value: Record, formSchemas: { varia const itemValue = value[formSchema.variable] if ((formSchema.default !== undefined) && (value === undefined || itemValue === null || itemValue === '' || itemValue === undefined)) newValues[formSchema.variable] = formSchema.default + + // Fix: Convert boolean field values to proper boolean type + if (formSchema.type === 'boolean' && itemValue !== undefined && itemValue !== null && itemValue !== '') { + if (typeof itemValue === 'string') + newValues[formSchema.variable] = itemValue === 'true' || itemValue === '1' || itemValue === 'True' + else if (typeof itemValue === 'number') + newValues[formSchema.variable] = itemValue === 1 + else if (typeof itemValue === 'boolean') + newValues[formSchema.variable] = itemValue + } }) return newValues }