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

Using semantic_form_for inputs in a sidebar partial double-renders inputs on resource show page #3613

Closed
johnmaxwell opened this issue Nov 12, 2014 · 9 comments

Comments

@johnmaxwell
Copy link
Contributor

I upgraded to a new version of AA, and a sidebar partial that I had written quite some time ago started showing its inputs doubled. I had another sidebar partial that was using plain form_tag that worked fine. I adapted the semantic_form_for version to not use the f.input calls and instead use the standard Rails form methods and it fixed the issue.

To be specific, I converted

= f.input :market, collection: Market.for_select

to

= f.select :market_id, Market.for_select.map {|m| [m.name, m.id]}, include_blank: false

Making this change fixed the problem.

To be clear, I am still using semantic_form_for in my partial; I just stopped using Formtastic's f.input helpers.

I think something changed in the past few weeks to cause this issue. Hopefully that's enough for you to go on, because I don't have time right now to dig into it.

@timoschilling
Copy link
Member

try this:

- f.input :market, collection: Market.for_select

@johnmaxwell
Copy link
Contributor Author

Yeah, that does fix it.

@johnmaxwell
Copy link
Contributor Author

Wait, should this be closed? Even though the double-output can be eliminated by switching from the echoing "=" to the non-echoing "-", formtastic works fine everywhere else with the echoing "=". In fact, that's how formtastic's documentation guides you to use it: https://github.com/justinfrench/formtastic#usage

It seems like this shouldn't be a problem in the first place.

@timoschilling timoschilling reopened this Nov 13, 2014
@johnmaxwell johnmaxwell changed the title Using semantic_form_for inputs in a sidebar partial double-renders inputs Using semantic_form_for inputs in a sidebar partial double-renders inputs on resource show page Nov 16, 2014
@johnmaxwell
Copy link
Contributor Author

Interesting development: It happens on the show page for a resource, but not on the index or edit pages. I added this partial as a sidebar to the Store admin resource inside the test-rails-app application.

<%= semantic_form_for [:admin, Store.new] do |f| %>
  <%= f.inputs do %>
    <%= f.input :name %>
  <% end %>
  <%= f.actions %>
<% end %>

Screenshot of the show page: https://www.dropbox.com/s/pe41ayd8q3e2mcg/Screenshot%202014-11-15%2021.51.25.png?dl=0
Screenshot of the index page: https://www.dropbox.com/s/nh7bif2ts51eckm/Screenshot%202014-11-15%2021.51.36.png?dl=0

@johnmaxwell
Copy link
Contributor Author

It's somehow related to active_admin_comments_for. If that renders on the same show page, then it doubles the sidebar form input. If it isn't on the page, then the sidebar form input is displayed correctly.

@johnmaxwell
Copy link
Contributor Author

Somehow active_admin_form_for being used in the show resource is causing the problem. It's important to note that you have to have to call f.inputs within it to trigger the issue. You can replicate using the partial above like this:

ActiveAdmin.register Store do

  if Rails::VERSION::MAJOR == 4
    permit_params :name
  end

  index pagination_total: false

  show do
    active_admin_form_for(Store.new, url: "/admin") do |f|
      f.inputs do
      end
    end
  end

  sidebar :form, partial: "sidebar_form"
end

So it's happening consistently on the show page because the Comments module uses active_admin_form_for

@johnmaxwell
Copy link
Contributor Author

Could this be related to #3486 ?

@timoschilling
Copy link
Member

Yes it's related to #3486, I hope @varyonic find some time to look on all Forms labeled tickets.

@vraravam
Copy link

I'm having the same issue - and had to revert to using the non-arbre style. Converting to the included arbre-style of forms within AA exposes this issue on my codebase.

form do |f|
	f.semantic_errors(*f.object.errors.keys)

	f.inputs I18n.t('activerecord.models.customer', count: 1) do
		f.input :name, input_html: { autofocus: true }
		f.input :email, as: :email
		f.input :mobile_no, as: :phone

		f.semantic_fields_for :customer_meta, f.object.customer_meta || f.object.build_customer_meta do |fi|
			fi.input :alternate_no, as: :phone
		end
	end

	f.actions
end

This(^^^) works; while this(vvv) does not:

form do |f|
	semantic_errors(*f.object.errors.keys)

	inputs I18n.t('activerecord.models.customer', count: 1) do
		input :name, input_html: { autofocus: true }
		input :email, as: :email
		input :mobile_no, as: :phone

		semantic_fields_for :customer_meta, f.object.customer_meta || f.object.build_customer_meta do |fi|
			input :alternate_no, as: :phone
		end
	end

	actions
end

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