Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails simple_form: custom input id

Tags:

I want to put several forms generated with Rails simple_form on a one page, and operate on them with javascript. However simple_form generated same ids for respective inputs in forms. Thus I want to replace generated id with my own.

Now I have a line:

<%= f.input :id, :as => :hidden, :html => {:value => @question.id} %> 

and HTML output (for @question.id=1):

<input id="question_id" class="hidden" type="hidden" value="1" name="question[id]"> 

and I want to get:

<input id="question_id_1" class="hidden" type="hidden" value="1" name="question[id]"> 

question_id_1 is just an example. I want to be able to choose this id.

I use Rails 3 and simple_form 1.5.

like image 763
mrzasa Avatar asked Dec 29 '11 22:12

mrzasa


1 Answers

You're almost there.

The trick is in specifying the :input_html.

<%= f.input :id, :as => :hidden,       :input_html => {         :value => @question.id,         :id => "question_id_1"       } %> 
like image 77
Matthew Rudy Avatar answered Sep 28 '22 04:09

Matthew Rudy