Reputation: 1
On Rails 5 I'm populating a hidden_field_tag with a date using datepicker jQuery UI function. The view currently looks like this -
<script>
$( function() {
$('#datepicker').datepicker({
inline : true,
altField : "#date_search",
onSelect : function(){ $('#date_search').submit();}
});
});
</script>
(...)
<%= form_tag(escala_index_path, :method => :get ) do %>
<%= hidden_field_tag("date_search") %>
<%= submit_tag "Search", name: nil %>
<% end %>
Which is working fine. But I want to drop the submit_tag and make the form submit the date when it changes, since in a similar form with select_tag the :onchange option worked I tried:
<%= hidden_field_tag("date_search", "", :onchange => ("this.form.submit();")) %>
But nothing happens. Any tips on what I'm doing wrong?
Upvotes: 0
Views: 213
Reputation: 101811
$('#date_search').submit();
does not work since the submit event does not bubble up to the form.
$(function() {
$("#datepicker").datepicker({
inline : true,
altField : "#date_search",
onSelect : function(){ this.form.submit() }
});
});
Upvotes: 1