<%= error_messages_for @ingredient %>

<%= f.text_field :name, size: 40, required: true %>

<%= f.number_field :ref_amount, size: 8, required: true, min: 0 %> <%= f.select :ref_unit_id, unit_options, {label: '', required: true} %>

<%= f.select :group, group_options, required: true %>

<%= f.fields_for :nutrients, @nutrient do |ff| %>

<%= ff.select :quantity_id, quantity_options, label: (ff.index > 0 ? '' : :field_nutrients) %> <%= ff.number_field :amount, {size: 8, label: ''} %> <%= ff.select :unit_id, unit_options, label: '' %> <%= link_to t(".button_delete_nutrient"), '#', :class => 'icon icon-del', :style => "display:none", :onclick => "deleteNutrient("+ff.index.to_s+"); return false;" %>

<% end %>

<%= link_to t(".button_add_nutrient"), '#', :class => 'icon icon-add', :onclick => 'addNutrient(); return false;' %>

<%= javascript_tag do %> function addNutrient() { var row = $('#ingredient-form p.nutrient:last'); var id = parseInt(row.attr('data-id')) + 1; var new_row = row.clone().insertAfter(row); new_row.attr('data-id', id) new_row.find('input, select').val(''); new_row.find('label').text(''); if ($('#ingredient-form p.nutrient').length > 1) { $('#ingredient-form p.nutrient a.icon-del').show(); } else { $('#ingredient-form p.nutrient.icon-del').hide(); } } <% end %>