title: Submit a rails form with javascript
body: <p>I have the following form:</p>
  
  <pre><code> &lt;% category.child_categories.sort_by(&amp;:name).each do |child_category| %&gt;
       &lt;%= form_tag (search_path), :method =&gt; "get", class: "search-form" do %&gt;
           &lt;label for="checkData" style="cursor: pointer;" class="search"&gt;
             &lt;%= hidden_field_tag :shop_search, child_category.id %&gt;
               &lt;i class="fas fa-search"&gt;&lt;/i&gt; &lt;%= child_category.name %&gt;
            &lt;/label&gt;
       &lt;%= submit_tag '', :style =&gt; "display: none;" %&gt;
       &lt;% end %&gt;
   &lt;% end %&gt;
  </code></pre>
  
  <p>When I click on a label and if the cookies[:coordinates] does exist, then the form gets submitted with <code>$(this).parent('form.search-form').trigger('submit.rails');</code>:</p>
  
  <pre><code>$(".search").click(function(e){
      &lt;% if cookies[:coordinates].blank? %&gt;
          if (navigator.geolocation) {
              navigator.geolocation.getCurrentPosition(setGeoCookie, displayError);
          } else {
              alert("Geolocation is not supported by the browser you are currently using. Supported browsers: Chrome 5.0, Firefox 3.5, Internet Explorer 9.0, Opera 10.60, Safari 5.0");
          }
  
  
      function setGeoCookie(position) {
          let cookieName = "coordinates";
          let now = new Date();
          let time = now.getTime();
          time += 3600 * 5000;
          now.setTime(time);
          let cookie_val = position.coords.latitude + "|" + position.coords.longitude;
          document.cookie = cookieName +"=" + cookie_val + '; path=/';
          $(this).parent('form.search-form').trigger('submit.rails');
      }
  
  
      function displayError(error) {
          let errors = {
              1: 'error',
              2: 'Position unavailable',
              3: 'Request timeout'
          };
          alert("Error: " + errors[error.code]);
          window.location.reload(true)
  
      }
      getLocation();
      &lt;% else%&gt;
      $(this).parent('form.search-form').trigger('submit.rails');
      &lt;% end %&gt;
  });
  </code></pre>
  
  <p>And when the cookies[:coordinates] doesn't exist I have to create the cookie first and then trigger the form inside the <code>function setGeoCookie</code>. But for some odd reason the form is not being submitted. Any ideas what I might be doing wrong?</p>