fix: improve boolean field handling in plugin configuration forms (#23160)

Co-authored-by: crazywoola <427733928@qq.com>
This commit is contained in:
Alan Bustamante
2025-08-01 04:34:46 +02:00
committed by GitHub
parent 872ff3f1d4
commit c33741a5e9
2 changed files with 26 additions and 1 deletions

View File

@@ -47,7 +47,22 @@ const EndpointModal: FC<Props> = ({
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 (

View File

@@ -63,6 +63,16 @@ export const addDefaultValue = (value: Record<string, any>, 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
}