BooleanInput not saving in React-Admin

Photo by Steve Johnson from Pexels: https://www.pexels.com/photo/white-wall-927546/
Photo by Steve Johnson from Pexels: https://www.pexels.com/photo/white-wall-927546/

So I was having an issue in react-admin where the value of BooleanInput (e.g. a checkbox slider) was not saving to my backend.

Specifically when I left the input as unchecked when creating a new entry it wouldn’t pass the parameter of that checkbox (unchcked so false or 0) in the post body. I’m assuming that because this value had no value (null) then it didn’t see the need to send it.

To get around this, all I needed to do was to force the BooleanInput to be false by default, and then it was properly sending false to my backend if I left it unselected.

<BooleanInput source="is_proprietary" defaultValue={false} />

I’m hoping this helped someone out there.


Profile picture

Written by who lives and works in Wisconsin building useful things, and thinks that pineapple on pizza is okay. You should follow them on Twitter