<%= f.select :domain, domain_options, {required: true} %>
<% Quantity.domains.each_key do |d| %>
>
<%= f.select :parent_id, parent_options(d), {required: true,
label: :field_parent_quantity,
include_blank: t('.null_parent')} %>
<% end %>
<%= f.text_field :name, size: 25, required: true %>
<%= f.text_field :description, style: "width: 100%;" %>
<%= f.text_field :formula, placeholder: t('.formula_placeholder'),
style: "width: 100%;" %>
<%= f.check_box :primary %>
<%= javascript_tag do %>
function domainChange() {
box = $(this).closest('div');
box.find('[id^=parent_select_]').prop('disabled', true).hide();
box.find('[id^=parent_select_] select').attr('name', 'placeholder');
domain = $(this).val();
box.find('[id=parent_select_'+domain+']').prop('disabled', false).show();
box.find('[id=parent_select_'+domain+'] select')
.attr('name', 'quantity[parent_id]');
}
$('form').on('change', '#quantity_domain', domainChange);
//Firefox does not emit 'change' signal when preserving form over reload
$(document).ready(function() {
domainChange();
});
<% end %>