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

tabbing not working properly having nested objects #40

Open
alecslupu opened this issue Apr 14, 2020 · 2 comments
Open

tabbing not working properly having nested objects #40

alecslupu opened this issue Apr 14, 2020 · 2 comments

Comments

@alecslupu
Copy link

alecslupu commented Apr 14, 2020

When rails_admin_globalize_field widget is used within a nested object, it does not work properly, as the tabs are not properly switched.
In this particular case, there will be more DOM elements with the same id.
I have tried to inject an unique string within https://github.com/scarfacedeb/rails_admin_globalize_field/blob/master/lib/rails_admin_globalize_field/globalize_tabs.rb#L31 , however, the approach dis not worked as expected.
I think a different tab binding should be used.

Using:

  • rails_admin-2.0.2
  • rails_admin_globalize_field-1.2.0

===

Having the models set up like:

class Poll < ApplicationRecord
  has_many :poll_options, dependent: :destroy
  accepts_nested_attributes_for :translations, allow_destroy: true
end
class PollOption < ApplicationRecord
  translates :description, touch: true, versioning: :paper_trail
  accepts_nested_attributes_for :translations, allow_destroy: true
end

And the following Rails admin setup

  config.model "Poll" do
    parent "Post"
    edit do
     fields :poll_options
    end 
  end 

  config.model "PollOption" do
    configure :translations, :globalize_tabs
    nested do
      exclude_fields :translations
    end
  end

  config.model 'PollOption::Translation' do
    include_fields :locale, :description
  end

I get some some strange behavior regarding the tabbing when trying to add multiple Poll Option entries. The tabbing is activated on model level (meaning i can browse through the Poll Option forms), however, the translations (which are also tabbed are not working). when clicking on on the language, the selected tab becomes active, but the tab-pane is not being changed.

I get the same behavior when trying to edit a poll that has 2 options. The tab-panes in the second object is not correctly activated.

@alecslupu alecslupu changed the title tabbing not working properly having nested obects tabbing not working properly having nested objects Apr 14, 2020
@sasselin
Copy link

Overwrite views/rails_admin/main/_form_globalize_tabs.html.haml with this:

- uuid = SecureRandom.uuid
.controls
  %ul.nav.nav-tabs{ :style => 'margin-top:5px' }
    - field.tabs.each do |tab|
      %li{ class: ('active' if tab.active?) }
        = link_to tab.label, "#", data: { toggle: "tab",  target: "##{tab.id}-#{uuid}" }, class: ('text-danger' unless tab.valid?)

.tab-content
  - field.tabs.each do |tab|
    = form.fields_for field.name, tab.translation, wrapper: false do |f|
      .fields.tab-pane{ id: "#{tab.id}-#{uuid}", class: ('active' if tab.active?) }
        = f.generate(action: :nested, model_config: field.associated_model_config, nested_in: field)

@Tronerta
Copy link

Tronerta commented May 29, 2021

@sasselin It works, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants