:namespace does not add id to the form #975

Closed
amolpujari opened this Issue Oct 28, 2013 · 6 comments

4 participants

@amolpujari

No description provided.

@justinfrench

Can you provide more detail and an example please?

@amolpujari

simple, I wanted to access form element, I wanted to append some html to it. So needed handle to it. Though I had single form on the page, wanted to have a clear way to select it, so found :namespace would assign id=_ to it, but not found working

<%= semantic_form_for "", :url => "/admin/gateways/#{@gateway.id}/configure", :method => :put, :namespace => "configure" do |f| %>
    <fieldset class="actions" style="float:left;">
      <ol>
     .............

This I expected to add <form id="_configure", but it did not. It generates the following

<form accept-charset="UTF-8" action="/admin/gateways/2311/configure" class="formtastic " method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓"><input name="_method" type="hidden" value="put"><input name="authenticity_token" type="hidden" value="5Ahj8E3s/aRvUy0V6HNgVgVuHSMcJKO117HOJp4/o="></div>
    <fieldset class="actions" style="float:left;">
      <ol>
    .....

I ended up using $("form.formtastic")

@amolpujari

ohhh, sorry, I just read it up again, :namespace will add to each field or attribute/input but not the form itself.

Okeh, so how do I do it. adding some html or id to the form itself?

@r3bo0t

To add id, class, or some other html attributes to form itself, use html: { id: "whatever_id_you_want"}. Also @justinfrench already posted on stackoverflow http://stackoverflow.com/questions/2047497/formtastic-set-class-and-id-of-form. This might help I guess.

@dpehrson

I also just noticed that setting :namespace does not prefix the id attributes of actions either. It appears setting it only affects inputs and their respective labels.

@justinfrench
Owner

@sandeepkrao has answered the original question, so I'm going to close this. If @dpehrson or someone else would like to improve :namespace for future versions, I'd love to see a pull request. Thanks!

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