railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.87k stars 2.25k 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.