<% 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: 'subthresholds(event); return false;', class: 'threshold'} %> <% unless threshold_q.nil? %> <%= threshold_f.hidden_field :id %> <%= 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 %>