The dropdown menu in Foundation 5's top bar occasionally malfunctions, but seems to work properly after the webpage is refreshed

I have implemented a dropdown menu in my Rails app (Rails 4, Ruby 2) that utilizes Foundation 5. While the dropdown menu typically functions properly, there are instances where it fails to drop down seemingly at random. I have attempted to use both "hover" and "clickable" options, but encountered the same sporadic issues. Whenever the dropdown has failed, simply refreshing the page resolves the problem. However, this inconsistency is problematic for users and something I aim to resolve. Any suggestions on how to address this issue?

The code for the dropdown menu can be found in views/layouts/_header.html.erb and is rendered in application.html.erb:

<nav class="top-bar" data-topbar data-options="is_hover: false">
  <ul class="title-area">
    <li class="name">
      <h1><%= link_to 'What Key Am I In?', root_path %></h1>
    </li>
    <li class="toggle-topbar">Menu</li>
  </ul>

  <section class="top-bar-section">
    <!-- Right Nav Section -->
    <ul class="right">
      <li><a href="#">All Keys</a></li>
      <li><%= link_to 'All Chords', chords_path %></li>
      <li><%= link_to 'All Notes', notes_path %></li>
      <li class="divider"></li>
      <li class="has-dropdown">
        <% if current_user.nil? %>
          <li><%= link_to 'Sign up!', new_user_registration_path %></li>
          <li><%= link_to 'Log in', new_user_session_path %></li>
        <% else %>
          <a href="#"><%= current_user.username %></a>
          <ul class="dropdown">
            <li><%= link_to 'View profile', current_user %></li>
            <li><%= link_to 'Edit profile', edit_user_registration_path(current_user) %></li>
            <li class="divider"></li>
            <li><%= link_to 'Chords Pending Approval', chords_pending_approval_path %>
            <li class="divider"></li>
            <li><%= link_to "Logout", destroy_user_session_path, method: :delete %></li>
          </ul>
        <% end %>
      </li>
    </ul>
  </section>
</nav>

Answer №1

After disabling Turbolinks, the problem seems to have been resolved. It appears that Turbolinks was the culprit causing the issue, which is not uncommon as I've encountered similar issues in the past due to Turbolinks.

Answer №2

Did you remember to add the code below after including your foundation.js file? Also, have you included any other javascript plugins in your project? I encountered a similar issue with a JQuery image slider in the past and was able to resolve it by adding my code inside the braces. Hopefully, this information is helpful. If not, I can conduct further research to assist you!

     $(window).load(function() {}

Make sure to include this at the end of your file as well.

 <script src="js/foundation/foundation.js"></script>
 <script src="js/foundation/foundation.topbar.js"></script>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Loading a different webpage seamlessly without having to reload the current one

Here is a snippet of my code in okay.html: {% extends "sch/base.html" %} {% load staticfiles %} {% block content %} <div class="row" id="ada"> <form action="" method="post> {% csrf_token %} <div align="center" class="cont ...

What is the best way to access the current element in a loop function?

I'm facing an issue with a nested each function and I need help on how to refer to the current item when the if statement is triggered: // checking for empty array if(sameValArr.length === 0) { $(this).hide(); // hiding the current video thumbnail ...

Update the content within every <td> element using AJAX/JQUERY on a table created from JSP

I have a database filled with descriptions and corresponding ID numbers. The table displays them like this: index.jsp <table> <tr> <td>Name:</td> <td>Id:</td> </tr> <c:forEach items ...

Run a jQuery script that is inserted dynamically after the page has finished loading

I am currently working on a website that is utilizing ajax requests to dynamically update specific sections of the page. One particular request involves generating an extra jQuery script and injecting it into the document. I am struggling to find a soluti ...

Effective steps after Ajax request

Whenever a user clicks the "like" button, I perform a check in the database to see if they have already liked the photo. This check is done using ajax. If the photo has already been liked, the success message will indicate "already liked", otherwise it wi ...

Combining Bootstrap and @material-ui for a better UI experience!

Is there a way to apply Bootstrap classes to @material-ui components? For example, I am attempting to create a button and style it using both 'btn' and 'btn-primary' from Bootstrap. import { makeStyles } from "@material-ui/core&quo ...

The array is remaining empty

When I need to loop through a JSON file, I typically use the following code snippet: var list = new Array(); $.getJSON("json.js", function (data) { $.each(data, function () { $.each(this, function (k, v) { var list = new Array(); ...

Tips for accessing the content within a DIV tag in a new browser tab

$('.menu div.profile-btn').on('click', function () { $('.mainservice-page').fadeIn(1200); } The script above effectively displays the contents of the .mainservice-page div, but I would like to open them in a new tab. Is ...

Is there a way to display the title attribute when truncating a lengthy text in Vue?

Recently, I encountered an issue with my dynamically created table. I added the class truncate to the spans within the td elements to shorten the log sentences and implemented a title attribute to display the full sentence on hover. However, I noticed that ...

Unable to send form data to PHP script

Looking for assistance with passing a variable from a number input to a PHP page. HTML CODE <input type="number" class="count count-disco" name="quantity_disks" autocomplete="off" placeholder="0"> https://i.sstatic.net/BK3X9.png PHP and JQUERY CO ...

Why won't the CSS style in my HTML file display properly in Django?

I've been encountering an issue with my CSS file not working in Django, and I'm unsure of the reason behind it. Despite numerous attempts to troubleshoot, the problem persists. I have included {%load static%} at the beginning of my HTML file, and ...

Error encountered while using getElementsByTagName in Greasemonkey on a webpage built with extJS, showcasing a basic scenario

Currently, I am experimenting with Greasemonkey on a web-app that constructs the DOM step by step utilizing a substantial amount of Javascript and making use of the extJS library. When there is no Greasemonkey code in operation, the site loads as expected ...

Exploring the capabilities of the jQuery `val()` function alongside the dynamic framework

Whenever I have a JavaScript variable that contains HTML printed from a table on my server, I encounter issues when using it in a jQuery function like val(). The problem arises every time someone enters content with special characters like " or '. Thi ...

Is there a counterpart in jQuery for YUI, ASP.NET, or Google's DataSource functionality?

One feature I really admire about the YUI framework is its DataSource control. This control allows for seamless integration of data from different sources into various UI widgets in a standardized manner. For instance, you can easily populate a table, a ch ...

What is the best way to remove unnecessary space in a div when the content is smaller than the height, while still using overflow:auto?

HTML CODE <p>overflow:auto</p> <div class="auto">This code snippet will add a vertical scroll bar to the content within the div if it exceeds the height of the div. The background color is set to green, width and height are both 100px, ...

Tips for creating an HTML select form that allows the user to update a JSON value based on their selection

On my current HTML+JS webpage, I have manually set the starting coordinates (latitude and longitude) for a country in the West, North, East, and South direction: var WNES = { "W": 67.0, "N":37.5, "E": 99.0, "S": 5.0, "item":"India" }; However, I have rec ...

HTML structure consisting of a 3 by 3 grid

Creating a 3x3 grid with cells that have varying heights depending on content is proving to be challenging. Except for the cells marked with red arrows, the rest of the grid has fixed height in pixels. I attempted to build a 3x3 grid using divs to experi ...

Setting the transition time for adding or removing components in ReactJS CSS

As the list component changes in size based on its children, it tends to move around abruptly. Applying transition: 'all 0.3s ease' doesn't resolve this issue since it's the layout that is affected by the number of children rather than ...

Utilizing JQuery Mobile to assign event listeners to buttons generated dynamically

Upon receiving a json array from the server, I loop through it in jQuery and dynamically add buttons (with data-role="button") to a webpage. In each iteration, I call $("a[data-role='button']").button(). The issue arises when I need each button ...

Differences between Bootstrap 3.3.7 and Bootstrap 4

After successfully building my application on Bootstrap 4 and incorporating Bootstrap-Table and Bootstrap-DateTime picker plugins, I ran into display issues when trying out Bootstrap-Select. It was then that things went haywire. Upon closer investigation, ...