Reputation: 1314
In my app i have a form with 4 fields that records information about a friend. (see screenshot)
At the bottom i have a button that dynamically duplicates the form should the user want to enter another record.
They way i have it setup is sort of messy and will be extremely long should the user want to add lots of records.
Is there a cleaner way to do this? Maybe some sort of jquery table?
View code:
<div id="single_module">
<div class="pitch">
<h2>Step 3: Friends Birthdays</h2>
</div>
<form id="myForm">
<div id="input1" style="margin-bottom:4px;" class="clonedInput">
<%= simple_form_for @user, url: wizard_path do |f| %>
<div class="inputs">
<ul class="testss1">
<%= f.simple_fields_for :friends do |friend_f| %>
<li>
<%= friend_f.input :name %>
</li>
<li>
<%= friend_f.input :dob, :as => :date_picker, :label => 'Birthday', :input_html => { :class => 'special' } %>
<li>
<%= friend_f.input :gender, :collection => ['male','female'] %></li>
</li><li>
<%= friend_f.association :interests, :as => :select, :label => false %></li>
<%end%>
</div>
<div>
<input type="button" id="btnAdd" value="add another name" />
<input type="button" id="btnDel" value="remove name" />
</div>
</form>
<div class="actions">
<%= f.button :submit, 'Next Step', :class => 'btn btn-primary', %>
<br></br>
</div>
<%end%>
Upvotes: 0
Views: 233
Reputation: 3169
do you save each time when is done, add another friend click? why not to save you data even in temporary hidden field, then clear all data in your form and let user add another record?
Upvotes: 2