Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically adding elements to a form
    primarykey
    data
    text
    <p>My goal is to have a form where I fill in some details and then I can hit 'add question' which is a link that should dynamically add a question.</p> <p>i.e.</p> <hr> <p>Date:<br> Name:<br> Description: </p> <p><strong>Add a Question</strong></p> <p>Create </p> <hr> <p>my <b>_form.html.haml</b> starts off as such as such (this form is under views/interviews since my goal is to be able to add questions to an interview. However, questions can be used independently of interviews as well)</p> <pre><code>= form_for ([:posting, @interview]) do |ff|&lt;br&gt; - if @interview.errors.any? . . . (more fields) . . . .field{:id =&gt; "overall_questions"} =link_to "Add a Question", new_question_path, :remote =&gt; true %br/ %br/ .field{:id =&gt; "individual_questions"} =ff.label :whyyy =ff.fields_for :questions, @interview.questions do |builder| = render :partial =&gt; "question_fields" %br/ %br/ .actions = ff.submit </code></pre> <p><b>_question_fields.html.haml</b></p> <pre><code>.fields{:id =&gt; "question#{builder.object.id}"} =ff.label :content, "Question" =link_to "Remove", question_path(builder.object.id), :remote =&gt; true, :confirm =&gt; "Are you sure?", :method =&gt; :delete %br/ =ff.text_area :content, :rows =&gt; 3 </code></pre> <p>the :remote => true (from _form.html.haml) gets directed to my <b>questions_controller.rb</b></p> <pre><code>def new @question = Question.new respond_to :js end </code></pre> <p>this links to my <b>new.js.erb</b> file under views/questions</p> <pre><code>$('#individual_questions').clone().appendTo($('#overall_questions')) </code></pre> <p>The thing is, I'm not quite sure how to call the _question_fields.html.haml. I know the js.erb file works because I've been able to run alert boxes when clicking 'Add a question' and it also currently appends the Whyyy from the field with id individual questions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload