refactor: update radio component to handle boolean values instead of numeric (#24956)
This commit is contained in:
@@ -103,12 +103,6 @@ const BaseField = ({
|
|||||||
})
|
})
|
||||||
}, [values, show_on])
|
}, [values, show_on])
|
||||||
|
|
||||||
const booleanRadioValue = useMemo(() => {
|
|
||||||
if (value === null || value === undefined)
|
|
||||||
return undefined
|
|
||||||
return value ? 1 : 0
|
|
||||||
}, [value])
|
|
||||||
|
|
||||||
if (!show)
|
if (!show)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
@@ -215,11 +209,11 @@ const BaseField = ({
|
|||||||
formSchema.type === FormTypeEnum.boolean && (
|
formSchema.type === FormTypeEnum.boolean && (
|
||||||
<Radio.Group
|
<Radio.Group
|
||||||
className='flex w-fit items-center'
|
className='flex w-fit items-center'
|
||||||
value={booleanRadioValue}
|
value={value}
|
||||||
onChange={val => field.handleChange(val === 1)}
|
onChange={v => field.handleChange(v)}
|
||||||
>
|
>
|
||||||
<Radio value={1} className='!mr-1'>True</Radio>
|
<Radio value={true} className='!mr-1'>True</Radio>
|
||||||
<Radio value={0}>False</Radio>
|
<Radio value={false}>False</Radio>
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@@ -5,7 +5,7 @@ import cn from '@/utils/classnames'
|
|||||||
|
|
||||||
export type TRadioGroupProps = {
|
export type TRadioGroupProps = {
|
||||||
children?: ReactNode | ReactNode[]
|
children?: ReactNode | ReactNode[]
|
||||||
value?: string | number
|
value?: string | number | boolean
|
||||||
className?: string
|
className?: string
|
||||||
onChange?: (value: any) => void
|
onChange?: (value: any) => void
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ export type IRadioProps = {
|
|||||||
labelClassName?: string
|
labelClassName?: string
|
||||||
children?: string | ReactNode
|
children?: string | ReactNode
|
||||||
checked?: boolean
|
checked?: boolean
|
||||||
value?: string | number
|
value?: string | number | boolean
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
onChange?: (e?: IRadioProps['value']) => void
|
onChange?: (e?: IRadioProps['value']) => void
|
||||||
}
|
}
|
||||||
|
@@ -284,11 +284,11 @@ function Form<
|
|||||||
</div>
|
</div>
|
||||||
<Radio.Group
|
<Radio.Group
|
||||||
className='flex items-center'
|
className='flex items-center'
|
||||||
value={value[variable] === null ? undefined : (value[variable] ? 1 : 0)}
|
value={value[variable]}
|
||||||
onChange={val => handleFormChange(variable, val === 1)}
|
onChange={val => handleFormChange(variable, val)}
|
||||||
>
|
>
|
||||||
<Radio value={1} className='!mr-1'>True</Radio>
|
<Radio value={true} className='!mr-1'>True</Radio>
|
||||||
<Radio value={0}>False</Radio>
|
<Radio value={false}>False</Radio>
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
</div>
|
</div>
|
||||||
{fieldMoreInfo?.(formSchema)}
|
{fieldMoreInfo?.(formSchema)}
|
||||||
|
@@ -91,8 +91,8 @@ const ParameterItem: FC<ParameterItemProps> = ({
|
|||||||
numberInputRef.current!.value = `${num}`
|
numberInputRef.current!.value = `${num}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleRadioChange = (v: number) => {
|
const handleRadioChange = (v: boolean) => {
|
||||||
handleInputChange(v === 1)
|
handleInputChange(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleStringInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
const handleStringInputChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||||
@@ -187,11 +187,11 @@ const ParameterItem: FC<ParameterItemProps> = ({
|
|||||||
return (
|
return (
|
||||||
<Radio.Group
|
<Radio.Group
|
||||||
className='flex w-[178px] items-center'
|
className='flex w-[178px] items-center'
|
||||||
value={renderValue ? 1 : 0}
|
value={renderValue as boolean}
|
||||||
onChange={handleRadioChange}
|
onChange={handleRadioChange}
|
||||||
>
|
>
|
||||||
<Radio value={1} className='w-[83px]'>True</Radio>
|
<Radio value={true} className='w-[83px]'>True</Radio>
|
||||||
<Radio value={0} className='w-[83px]'>False</Radio>
|
<Radio value={false} className='w-[83px]'>False</Radio>
|
||||||
</Radio.Group>
|
</Radio.Group>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user