ruby on rails - JQuery ajax form submit resets select value and does not persist it -
i've got select field using filter results on table. when pick option select fires ajax , updates table... however, resets select once table has updated. if use text box filter don't run issue.
form:
<%= form_tag items_path, method: :get, class: "navbar-form search-form", remote: true %> <%= select_tag :search, options_from_collection_for_select(model.all, "id", "id"), include_blank: true, class: "form-control", id: "filter-key" %> <% end %>
js/jquery
$(document).ready(function(){ $(document).on("change", "#filter-key", function(){ var form = $('.search-form'); $.get(form.action, form.serialize(), null, 'script'); return false; }); });
something in script that's being returned must resetting select value. save value , put in ajax code.
var self = $(this); var oldvalue = self.val(); $.getscript(form.attr('action'), form.serialize(), function() { self.val(oldvalue); });