How do you get the Ruby on Rails generated id of a form element for reference in JavaScript?

前端 未结 8 891
無奈伤痛
無奈伤痛 2021-02-05 01:01

When using the form_for helper and a text_field call, Ruby on Rails will generate a unique id for the element that it outp

8条回答
  •  梦如初夏
    2021-02-05 01:33

    Look at the form builder options:

    <%= form_for @user do |f| %>
      <% form_css_id = "#" + f.options[:html][:id] %>
    <% end %>
    

    Options should at least include the following data: css class, id, http method and authenticity token.

提交回复
热议问题