简体   繁体   中英

Rails 5 - hidden_field_tag populated by JS not submiting form via :onchange

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?

$('#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() } 
  });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM