简体   繁体   中英

How do I dynamically add form fields (2 in one click) to my form in ruby on rails

I have 3 fields in my form I have a submit button and a button to "Add additional fields" I have the additional fields in a partial.

I am a beginner to a lot of this and am stuck with a beginner question: My question is :

When I click the "Add additional field" button, what is the process to add the additional fields? Preferably not re-rendering the form, which i believe requires javascript.

In html file

<div id= "show_page" style= "display:none">
   <%= render partial: "your_partial_page" %> 
</div>
link_to "Add additional field", '#', id: 'add_fields'

$('#add_fields').click(function(){ //add this code to your javascript file
  $('#show_page').show();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM