Skip to content

BooleanInput

Toggle switch for boolean values, leveraging shadcn’s Switch component.

import { BooleanInput } from '@/components/admin';
<BooleanInput source="is_published" />
PropRequiredTypeDefaultDescription
sourceRequiredstring-Field name
classNameOptionalstring-Wrapper classes
defaultValueOptionalbooleanfalseInitial value
disabledOptionalboolean-Disable control
formatOptionalfunction-Callback to convert the value from the form state to a boolean.
helperTextOptionalReactNode-Help text
labelOptionalstringInferredLabel text
parseOptionalfunction-Callback to convert the value from a boolean to the form state.
validateOptionalValidator | Validator[]-Validation

<BooleanInput> expects the form state value to be a boolean (true or false). If you want to use it for non-boolean values, you can use the format and parse props to convert them.

The format prop accepts a callback taking the value from the form state, and returning the input value (which should be a boolean).

The parse prop accepts a callback taking the value from the input (which is a boolean), and returning the value to put in the form state.

form state value --> format --> form input value (boolean)
form input value (boolean) ---> parse ---> form state value

For example, you might want to store 1 and 0 in the form state instead of true and false.

<BooleanInput
source="is_active"
format={(value) => value === 1}
parse={(value) => (value ? 1 : 0)}
/>