railsadminteam / rails_admin

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

Mongoid embedded document boolean selector does not work #3554

Closed rpalackas closed 2 months ago

rpalackas commented 1 year ago

Describe the bug When a mongoid document has an embedded class the boolean selector doesn't work on new or edit

Reproduction steps Create mongoid class with embedded document Embedded document needs to have a Mongoid::Boolean field Add the embedded document in accepts_nested_attributes_for Open edit or create for the parent document in rails admin Clicking any of the buttons for the boolean won't change your selection

Expected behavior Clicking the buttons will change the selection

Additional context Digging into the html it seems to be that the label field has an incorrect for value: What rails admin creates:

<input class="btn-check" type="radio" value="1" name="parent_class[embedded_class_attributes][field_name]" id="parent_class_embedded_class_attributes_field_name_1">
<label for="parent_class[embedded_class_attributes]_field_name_1" class="success btn btn-outline-success">
<span class="fas fa-check"></span>
</label>

What it should be:

<input class="btn-check" type="radio" value="1" name="parent_class[embedded_class_attributes][field_name]" id="parent_class_embedded_class_attributes_field_name_1">
<label for="parent_class_embedded_class_attributes_field_name_1" class="success btn btn-outline-success">
<span class="fas fa-check"></span>
</label>

manually updating that label tag for attribute via admin tools fixes the problem.

rpalackas commented 1 year ago

I've resolved the issue locally and created a PR with my fix here: https://github.com/railsadminteam/rails_admin/pull/3555 I know your contributions page requests specs for the issue however I followed the contributions guide to setup and run specs locally and they're all failing with:

An error occurred while loading ./spec/integration/fields/wysihtml5_spec.rb. - Did you mean?
                    rspec ./spec/integration/fields/time_spec.rb
                    rspec ./spec/integration/fields/enum_spec.rb
                    rspec ./spec/integration/fields/simple_mde_spec.rb

Failure/Error: require 'sprockets/railtie'

LoadError:
  cannot load such file -- sprockets/railtie
# ./spec/dummy_app/config/application.rb:22:in `require'
# ./spec/dummy_app/config/application.rb:22:in `<top (required)>'
# ./spec/dummy_app/config/environment.rb:4:in `require'
# ./spec/dummy_app/config/environment.rb:4:in `<top (required)>'
# ./spec/spec_helper.rb:30:in `require'
# ./spec/spec_helper.rb:30:in `<top (required)>'
# ./spec/integration/fields/wysihtml5_spec.rb:3:in `require'
# ./spec/integration/fields/wysihtml5_spec.rb:3:in `<top (required)>'
/Users/richardpalackas/rails_admin/spec/spec_helper.rb:5: warning: already initialized constant CI_ORM
/Users/richardpalackas/rails_admin/spec/spec_helper.rb:5: warning: previous definition of CI_ORM was here
/Users/richardpalackas/rails_admin/spec/spec_helper.rb:6: warning: already initialized constant CI_TARGET_ORMS
/Users/richardpalackas/rails_admin/spec/spec_helper.rb:6: warning: previous definition of CI_TARGET_ORMS was here
/Users/richardpalackas/rails_admin/spec/spec_helper.rb:7: warning: already initialized constant PK_COLUMN
/Users/richardpalackas/rails_admin/spec/spec_helper.rb:7: warning: previous definition of PK_COLUMN was here

feel free to update the PR to meet your requirements

mshibuya commented 1 year ago

Please refer to CONTRIBUTING.md, which got updated recently.

rpalackas commented 11 months ago

Sorry it's been so long since I updated this. Finally had some time to work on the specs

mshibuya commented 2 months ago

Fixed by #3555.