railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.9k stars 2.26k forks source link

Non nullable boolean UI not showing checkmark #3612

Open gabrieletassoni opened 1 year ago

gabrieletassoni commented 1 year ago

Describe the bug On the Create and Edit UIs the checkboxes for non nullable boolean fields does not seem to wokr, clicking on them does not show a checkmark.

Reproduction steps Add a non nullable field to a model (in this case User)

add_column :users, :admin, :boolean, null: false, default: false

Run rails s Open the browser to http://localhost:3000 and navigate to User page generated by rails admin. Click on "Create +" button. The admin field created in the migration, does not work as expected.

Expected behavior I expect to see the checkmark appear if I click on it.

Additional context

mathieulajoienoel commented 1 year ago

I'm having the exact same issue for rails_admin 3.1.1 and rails 7.0.4.

mathieulajoienoel commented 1 year ago

I fixed it on my side for now by adding attribute :your_bool_field_here, ActiveModel::Type::Boolean.new in my model.

I think the problem is in https://github.com/railsadminteam/rails_admin/blob/master/lib/rails_admin/config/fields/types/boolean.rb function form_value. The value was '1' instead of true. Telling active_record that it was a boolean did the trick, but it was the first time I had to do that.

benhutton commented 1 month ago

any updates here? This is still broken for me!

mshibuya commented 1 month ago

I've added a spec for this, but as you can see it's working. https://github.com/railsadminteam/rails_admin/commit/10bf495f2e69c7dcbccb360026ee875461d1f22f

Are you sure that you're using the column type boolean, not integer or something?

benhutton commented 1 month ago

@mshibuya I realized our use case actually diverges just a bit. We are using store_accessor :document, :my_boolean_field. Things don't work great in that scenario, even though we are marking the field as :boolean

Ideally, nullable and nonnullable would be something that has an override config. OR, :nullable_boolean would be a different type