1
0
This repository has been archived on 2023-12-07. You can view files and clone it, but cannot push or open issues or pull requests.
body_tracking/app/views/targets/_thresholds_form.html.erb
cryptogopher bea0a8371d WIP Targets #edit/#update
NestedUniqueness properly restores collection.target
2021-04-23 19:19:44 +02:00

30 lines
1.5 KiB
Plaintext

<% target_f.object.thresholds.new unless last_quantity.leaf? %>
<%= target_f.fields_for :thresholds, index: '', child_index: '' do |threshold_f| %>
<% threshold_q = threshold_f.object.quantity %>
<% parent_id = threshold_q.nil? ? last_quantity.id : threshold_q.parent_id %>
<%= threshold_f.collection_select :quantity_id,
@project.quantities.target.children_of(parent_id),
:id, :name,
{include_blank: parent_id.nil? ? false : '.', required: true, no_label: true},
{autocomplete: 'off',
onchange: "$.ajax({
url: '#{project_subthresholds_path(@project, parent_id: parent_id)}',
data: 'quantity_id=' + $(this).val(),
dataType: 'html',
success: function(data) {
$(event.target).nextAll().addBack().last().after(data).end().remove();
}
});
return false;"} %>
<%# TODO: update above ajax with -1/no change/+1 logic based on copying existing threshold and proper ID/destroy handling %>
<%# {autocomplete: 'off',
data: {remote: true, url: subthresholds_project_targets_path(parent_id: parent_id)}} %>
<% unless threshold_q.nil? %>
<%= threshold_f.hidden_field :_destroy %>
<%= threshold_f.number_field :value, {size: 8, step: :any, no_label: true} %>
<%= threshold_f.collection_select :unit_id, @project.units, :id, :shortname,
{no_label: true} %>
<% end %>
<% end %>