%1 Only works in name attribute not class/id/etc? #790

Closed
ryanisinallofus opened this Issue Feb 2, 2012 · 6 comments

Comments

Projects
None yet
3 participants

<%= semantic_form_for @post do |f| %>
<%= f.inputs %>
<%= f.inputs :class => 'Category #%i', :for => :categories %>
<%= f.actions %>
<% end %>

That isn't supposed work?

Owner

justinfrench commented Feb 2, 2012

I don't think that was ever a feature. What's your use case?

It's common to give the listed element unique IDs for javascript manipulation.

Formtastic uses fieldsets inside a wrapper li.input for nested records:

<li class="inputs">
  <fieldset>...</fieldset>
  <fieldset>...</fieldset>
  <fieldset>...</fieldset>
</li>

I can't add unique classes to those fieldsets so I can't do much with them in javascript unless I go in and search for a unique id then back out and grab the fieldset that way. Not super efficient.

= f.inputs :class=>"ticket_type type_%i", :name => 'Category_%i', :for => :ticket_types do |tt|

It would be cool if you could do something like the above or below:

= f.inputs :wrapper_html=>{:class=>"ticket_type type_%i", :for => :ticket_types do |tt|

The output might be:

<li class="inputs">
  <fieldset class="ticket_type type_1">...</fieldset>
  <fieldset class="ticket_type type_2">...</fieldset>
  <fieldset class="ticket_type type_3">...</fieldset>
</li>

Or if both options worked:

= f.inputs :class="ticket_type type_%i", :wrapper_html=>{:class=>"ticket_types", :for => :ticket_types do |tt|
<li class="inputs ticket_types">
  <fieldset class="ticket_type type_1">...</fieldset>
  <fieldset class="ticket_type type_2">...</fieldset>
  <fieldset class="ticket_type type_3">...</fieldset>
</li>

Something like that anyway.

Thanks for your response,
Ryan

Owner

justinfrench commented Feb 2, 2012

Wondering if there shouldn't just be a unique id on each field set, rather than you having to do this. Either way, I'd accept a patch if you're interested. Unique classes seems a bit, errr, strange, but ids make sense.

I got around it by using some longer JQuery selectors but I think this would be an awesome feature. Got the OK to work on it at work next time I need it though!

Contributor

mhuggins commented Feb 13, 2012

@ryanisinallofus - Looks like this is a duplicate of #771. I submitted pull request #798, which provides a solution for accessing the current nested attribute index, assuming it is pulled in. :)

Owner

justinfrench commented Feb 14, 2012

@mhuggins agree, your patch solves this great, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment