Added nutrient add on ingredient form
This commit is contained in:
parent
f039917d0e
commit
dd8c4f2cd1
@ -8,10 +8,33 @@
|
||||
</p>
|
||||
<p><%= f.select :group, group_options, required: true %></p>
|
||||
<%= f.fields_for :nutrients, @nutrient do |ff| %>
|
||||
<p>
|
||||
<%= ff.select :quantity_id, quantity_options, {label: '', required: true} %>
|
||||
<%= ff.number_field :amount, {size: 8, label: '', required: true} %>
|
||||
<%= ff.select :unit_id, unit_options, {label: '', required: true} %>
|
||||
<p class="nutrient" data-id="<%= ff.index %>">
|
||||
<%= 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;" %>
|
||||
</p>
|
||||
<% end %>
|
||||
<p><%= link_to t(".button_add_nutrient"), '#', :class => 'icon icon-add',
|
||||
:onclick => 'addNutrient(); return false;' %></p>
|
||||
</div>
|
||||
|
||||
<%= 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 %>
|
||||
|
@ -4,6 +4,7 @@ en:
|
||||
field_action: 'Action'
|
||||
field_ref_amount: 'Reference amount'
|
||||
field_group: 'Group'
|
||||
field_nutrients: 'Nutrients:'
|
||||
field_domain: 'Domain'
|
||||
field_parent_quantity: 'Parent'
|
||||
field_shortname: 'Short name'
|
||||
@ -32,6 +33,8 @@ en:
|
||||
heading: 'Ingredients'
|
||||
heading_new_ingredient: 'New ingredient'
|
||||
form:
|
||||
button_add_nutrient: 'Add nutrient'
|
||||
button_delete_nutrient: 'Delete'
|
||||
groups:
|
||||
meat: 'meat'
|
||||
quantities:
|
||||
|
Reference in New Issue
Block a user