2

I would like the id for my input to be user[email] and not user_email. But everything I try doesn't work.

I am using the latest version of Devise for these gems.

This is my form:

  <%= form_for(resource, :as => resource_name, :class => "send-with-ajax", :url => user_registration_path(resource), :validate => true, :html => { :id => 'user_new' }) do |f| %>
                    <div class="six columns alpha"> 
      <%= f.text_field :email, :id => 'user[email]', :placeholder => "your-email@address.com", :input_html => {:autofocus => true}, :validate => true %>
                        </div>              
                        <div class="three columns sign-up alpha">
      <%= f.submit :label => "Submit", :value => "Sign Me Up!" %>
                          <div class="ajax-response"><%= devise_error_messages! %></div>
      </div>
  <% end %>

This is the HTML produced:

<form accept-charset="UTF-8" action="/users" class="formtastic user" data-validate="true" id="user_new" method="post" novalidate="novalidate"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="khstyw72jj44kkhaskdya3hkb3ba3lkxmw4=" /></div>
                        <div class="six columns alpha"> 
              <input data-validate="true" id="user_email" input_html="{:autofocus=&gt;true}" name="user[email]" placeholder="your-email@address.com" size="30" type="text" />
                            </div>              
                            <div class="three columns sign-up alpha">
              <input label="Submit" name="commit" type="submit" value="Sign Me Up!" />
                              <div class="ajax-response"></div>
              </div>
</form>

Thoughts?

marcamillion
  • 32,933
  • 55
  • 189
  • 380
  • 1
    I thought specifying id like you did would override the default, guess not. So I can't help you - but wanted to point out `input_html => {:autofocus => true}` is not working as you expect either. I would tend to live with the default rails naming here, fighting rails on this stuff can hurt. – house9 Jun 12 '12 at 21:24
  • What does it do? How do I force a re-load locally? I took out `:input_html =>` and it doesn't reflect when I refresh my page. – marcamillion Jun 12 '12 at 21:32

2 Answers2

2

ID cannot contain square brackets, so it might be the cause, that Rails changes it.

See: What are valid values for the id attribute in HTML? and What characters are allowed in DOM IDs?

Community
  • 1
  • 1
mrzasa
  • 22,895
  • 11
  • 56
  • 94
0

Seems I had to restart my server to get the form_helper changes to be reflected.

So :id => user[email] does work.

marcamillion
  • 32,933
  • 55
  • 189
  • 380