Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: editing nullable boolean forces it to false #3145

Closed
sedubois opened this issue May 25, 2019 · 7 comments
Closed

Bug: editing nullable boolean forces it to false #3145

sedubois opened this issue May 25, 2019 · 7 comments
Milestone

Comments

@sedubois
Copy link
Contributor

sedubois commented May 25, 2019

When a model has a boolean which can be nil, the "Show" tab indeed shows the boolean as nil with the help of a grey icon:

Screenshot 2019-05-25 at 15 43 12

However in the Edit tab, the value is displayed as an unticked checkbox instead of reflecting the fact that the value is nil:

Screenshot 2019-05-25 at 15 43 24

And when saving the Edit form, it then applies the value false to the field, instead of keeping it nil as it should. It means that currently I cannot use rails_admin to edit my records' other fields, out of fear of inadvertently modifying these boolean values which should stay nil.

@RocKhalil
Copy link
Contributor

What's the difference between having a boolean set as nil or false ? both cases it's a false statement.

@sedubois
Copy link
Contributor Author

sedubois commented Jun 3, 2019

nil can be used to represent the absence of information, false represents information. Anyway the Ruby language itself allows booleans fields to have those 3 values, just as many other languages allow as well. At the very least the editor shouldn't coerce nil fields into false.

@RocKhalil
Copy link
Contributor

Yup, totally get that. However, how can you know if the value was set by the user as false or as nil ? Maybe having a dropdown is a better option than a checkbox ?

@sedubois
Copy link
Contributor Author

sedubois commented Jun 3, 2019

Maybe use 3 radio buttons?

@RocKhalil
Copy link
Contributor

Good idea;

When nullable is set to false, we can use checkbox; otherwise, 3 radio buttons 👍

@nick-bigger
Copy link

I ran into this same issue! While it is being worked on, I have a basic workaround:

field :boolean_field, :enum do
  enum do
      [['True',true],['False',false],['Null',nil]]
  end
end

Unfortunately, no option will show in the dropdown for 'Null', but the field will show 'Optional' and can be cleared and saved correctly. And on the show page 'Null' will show correctly. Hope this helps!

@yuvalt
Copy link

yuvalt commented Aug 28, 2020

What worked for me is:

def boolean_field_enum
    [['True',true],['False',false],['Null',nil]]
end

@mshibuya mshibuya added this to the 3.0.0 milestone Oct 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants