Quantity parent options are updated through UJS
This commit is contained in:
@@ -1,35 +1,16 @@
|
||||
<%= error_messages_for @quantity %>
|
||||
|
||||
<div class="box tabular">
|
||||
<p><%= f.select :domain, domain_options, {required: true} %></p>
|
||||
<% Quantity.domains.each_key do |d| %>
|
||||
<div id="parent_select_<%= d %>" <%= 'style=display:none;' if @quantity.domain != d %>>
|
||||
<p><%= f.select :parent_id, parent_options(d), {required: true,
|
||||
label: :field_parent_quantity,
|
||||
include_blank: t('.null_parent')} %></p>
|
||||
</div>
|
||||
<% end %>
|
||||
<p><%= f.select :domain, domain_options, {required: true}, data: {
|
||||
remote: true,
|
||||
url: parents_project_quantities_path(@project),
|
||||
params: "form=#{f.options[:html][:id]}"
|
||||
} %></p>
|
||||
<p><%= f.select :parent_id, parent_options(@quantity.domain),
|
||||
{required: true, label: :field_parent_quantity, include_blank: t('.null_parent')} %></p>
|
||||
<p><%= f.text_field :name, size: 25, required: true %></p>
|
||||
<p><%= f.text_field :description, style: "width: 100%;" %></p>
|
||||
<p><%= f.text_field :formula, placeholder: t('.formula_placeholder'),
|
||||
style: "width: 100%;" %></p>
|
||||
<p><%= f.check_box :primary %></p>
|
||||
</div>
|
||||
|
||||
<%= 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 %>
|
||||
|
||||
5
app/views/quantities/parents.js.erb
Normal file
5
app/views/quantities/parents.js.erb
Normal file
@@ -0,0 +1,5 @@
|
||||
$('<%= "##{@form} " if @form %>#quantity_parent_id').empty().append(
|
||||
'<%= escape_javascript(options_for_select(
|
||||
parent_options(@domain).unshift([t('quantities.form.null_parent'), nil])
|
||||
)) %>'
|
||||
);
|
||||
@@ -1,3 +1,4 @@
|
||||
$('div[id^=flash_]').remove();
|
||||
$('#content').prepend('<%= escape_javascript(render_flash_messages) %>');
|
||||
$('#quantities').html('<%= escape_javascript(render :partial => 'quantities/index') %>');
|
||||
$('#quantity_domain').trigger('change');
|
||||
|
||||
Reference in New Issue
Block a user