Quantity form parent list narrowed to same domain
This commit is contained in:
parent
8ea838b380
commit
ffd38195a6
@ -6,8 +6,8 @@ module QuantitiesHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parent_options
|
def parent_options(domain)
|
||||||
options = nested_set_options(@quantities, @quantity) do |i|
|
options = nested_set_options(@quantities.send(domain), @quantity) do |i|
|
||||||
raw("#{' ' * i.level}#{i.name}")
|
raw("#{' ' * i.level}#{i.name}")
|
||||||
end
|
end
|
||||||
options.unshift([t('.null_parent'), nil])
|
options.unshift([t('.null_parent'), nil])
|
||||||
|
@ -2,9 +2,25 @@
|
|||||||
|
|
||||||
<div class="box tabular">
|
<div class="box tabular">
|
||||||
<p><%= f.select :domain, domain_options, required: true %></p>
|
<p><%= f.select :domain, domain_options, required: true %></p>
|
||||||
<p>
|
<% Quantity.domains.each_key do |d| %>
|
||||||
<%= f.select :parent_id, parent_options, required: true, label: :field_parent_quantity %>
|
<div id="parent_select_<%= d %>" style="display: none">
|
||||||
</p>
|
<p><%= f.select :parent_id, parent_options(d),
|
||||||
|
{required: true, label: :field_parent_quantity} %></p>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
<p><%= f.text_field :name, size: 25, required: true %></p>
|
<p><%= f.text_field :name, size: 25, required: true %></p>
|
||||||
<p><%= f.text_field :description, size: 200 %></p>
|
<p><%= f.text_field :description, size: 200 %></p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%= javascript_tag do %>
|
||||||
|
function domainChange() {
|
||||||
|
$('[id^=parent_select_]').prop('disabled', true).hide();
|
||||||
|
$('[id=parent_select_'+$('#quantity_domain option:selected').val()+']')
|
||||||
|
.prop('disabled', false).show();
|
||||||
|
}
|
||||||
|
$('#quantity-form').on('click', '#quantity_domain', domainChange);
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
domainChange();
|
||||||
|
});
|
||||||
|
<% end %>
|
||||||
|
Reference in New Issue
Block a user