0

When I click a field in a dropdown menu, the menu closes. I've seen a few questions relating to this (here and here) but the stop propagation wasn't working for me.

This is the html for my dropdown.

<div id="shifted_navbar_left">
      <a href="#" class="dropdown-toggle" data-toggle="dropdown">Log-In <b class="caret"></b></a>
      <ul class="dropdown-menu">
        <div id="dropdown_log_in">
          <h3> Engineer Sign-in</h3>
          <%= form_for(:engineer, :url => new_session_path(:engineer)) do |f| %>
            <%= f.label :email %> <br>
            <%= f.text_field :email %> <br />
            <%= f.label :password %> <br>
            <%= f.password_field :password%> <br />
            <%= f.check_box :remember_me %> 
            <%= f.label :remember_me %> <br />
            <%= f.submit 'Sign in', class: "btn btn-primary"%> <br />
            <%= link_to "Forgot your password?", new_password_path(:engineer) %>
          <% end %>
        </div>
      </ul>
  </div>

I am calling

<script type="text/javascript">
$('.dropdown-menu input, .dropdown-menu label').click(function(e) {
    e.stopPropagation();
});
</script>

from my application.html.erb header file section. The dropdown still disappears on click! I need to pick up my javascript game, but I feel like this should be working.. Is there something in rails that is blocking the javascript from running?

gemfile

#Use jquery as the JavaScript library
 gem 'jquery-rails'
 gem 'turbolinks'
 gem 'jquery-turbolinks'

My application.html.erb tags

<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
Community
  • 1
  • 1
Peege151
  • 1,562
  • 2
  • 21
  • 45

0 Answers0