``Is anyone else experiencing issues with the Laravel bootstrap dropdown not functioning correctly?

This is the navigation bar code:

<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
    <a class="navbar-brand" href="/teashirt/public/">TeaShirt</a>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsExampleDefault" aria-controls="navbarsExampleDefault" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarsExampleDefault">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item active">
                <a class="nav-link" href="/teashirt/public/">Home <span class="sr-only">(current)</span></a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="/teashirt/public/design">Desing your Teashirt</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="/teashirt/public/about">About Us</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="/teashirt/public/contact">Contact</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="/teashirt/public/checkout">Checkout</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" href="/teashirt/public/cart" tabindex="-1" aria-disabled="true">Cart</a>
            </li>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="dropdown01" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Guest!</a>
                <div class="dropdown-menu" aria-labelledby="dropdown01">
                    <a class="dropdown-item" href="#">Profile</a>
                    <a class="dropdown-item" href="#">Another action</a>
                    <a class="dropdown-item" href="#">Logout</a>
                </div>
            </li>
        </ul>
        <form class="form-inline my-2 my-lg-0">
            <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search">
            <button class="btn btn-secondary my-2 my-sm-0" type="submit">Search</button>
        </form>
    </div>
</nav>

Below is the Bootstrap JavaScript code:

window._ = require('lodash');

/**
 * We'll load jQuery and the Bootstrap jQuery plugin which provides support
 * for JavaScript based Bootstrap features such as modals and tabs. This
 * code may be modified to fit the specific needs of your application.
 */

try {
    window.Popper = require('popper.js').default;
    window.$ = window.jQuery = require('jquery');

    require('bootstrap');
} catch (e) {}

/**
 * We'll load the axios HTTP library which allows us to easily issue requests
 * to our Laravel back-end. This library automatically handles sending the
 * CSRF token as a header based on the value of the "XSRF" token cookie.
 */

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

Here is the app.js content:

require('./bootstrap');

I tried replacing require with import, but it didn't work.

I have also attempted popper upgrade and composer update, but nothing seems to fix the issue.

The problem I'm facing is that the dropdown menu in the navbar only goes to the link /# when clicked, regardless of browser used (IE or Chrome).

Answer №1

After analyzing your files, it seems that your issue may be related to one of the following possibilities:

1) The problem could be with sourcemaps in your webpack.mix configuration. Try the following code snippet:

const mix = require('laravel-mix');

mix.setPublicPath('public')
.setResourceRoot('../') // Adjusts asset paths in CSS relative to the CSS file
.js('resources/js/app.js', 'public/js')
.sass('resources/sass/app.scss', 'public/css')
.sourceMaps();

2) Ensure that you do not have any ad blockers enabled on your browser, as they may interfere with the loading of certain js files.

3) Modify your bootstrap.js script with the following changes:

import _ from 'lodash';
import $ from 'jquery';
import 'popper.js'; // Needed for Bootstrap 4
import 'bootstrap';

window.$ = window.jQuery = $;
window._ = _; // Utilizing Lodash

window.axios = require('axios');

window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';

I hope these solutions prove helpful. Please let me know which one resolves your issue.

Answer №2

It appears that the answer has not been fully resolved, as the current solution is not entirely satisfactory. I encountered the error while setting up a new Laravel 7 project with composer, running "artisan ui bootstrap", and then using npm install && npm run dev:

The error occurred when trying to use a collapse component

This is the value of the variable 'config'

This issue may be related to webpack, similar behavior can be seen here: https://github.com/webpack/webpack/issues/10504

I have not yet found a solution - currently experimenting with different Laravel Mix, jQuery, and Bootstrap versions.

Answer №3

My issue was resolved by inserting this code right before the `</body>` closing tags:

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>

I had actually attempted this solution in the past but for some reason, it didn't work then. Now, I can't pinpoint why it failed before but is effective now.

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

How can one ascertain the dimensions of the video margins within an embed-responsive video container?

I am in search of a solution to extract information from within the embed responsive element. When it comes to embed-responsive video elements, they automatically include internal margins on either the x or y axis to maintain the aspect ratio of the video ...

Transferring Information from Angular Interface to NodeJS through a JSON Document

I am currently working on establishing a connection between an AngularJS front end and a NodeJS back end application. The main objective is to manipulate data in a JSON file instead of a traditional database. I have attempted to set up the post method on ...

What is the best way to resume a Jquery function if it has not

How do I make my form alert re-trigger when the user clicks the button again if the input is still empty? What I've tried: After clicking the button, it checks if the inputs are empty and shows an alert. However, once the alert appears, if I click th ...

Error in Rails due to a Javascript issue

My journey with learning Javascript started by following an easy game tutorial on RoR. I encountered an error in index.html.erb file which led me to a helpful video tutorial here. <script> var ctx, canvas; var data; window.onload = fun ...

Learn the process of fetching checkbox values using JavaScript with this snippet

Is it possible to retrieve the name of the selected checkbox values/labels from the following code: <input id ="abc" value="abeexch" type ="checkbox"> <input id ="nam" value="suns" type ="checkbox"> If a checkbox is selected, how can I obtain ...

Updating data in a table upon submission of a form in Rails

In my Rails 3.2 application, I am displaying a table of results using the @jobs variable passed to the view from a SQL query. I want to add a button that will trigger a controller action when clicked. The action should perform some database operations and ...

Increase the width in a leftward direction

I am looking to increase the width from right to left. <div dir="rtl" id="progress"> <dt id='dt'></dt> <dd id='dd'></dd> </div> The ultimate objective here is to have this progress bar progr ...

Concealing a division element if there is no content inside of it

As a newcomer to jQuery, I am experimenting with setting up a code that hides a div when the 'innerHTML' is null. However, my attempt using the code below is not working. Can anyone point out where I might be going wrong? if (($("#php-errors").h ...

The React popup window refuses to close on mobile devices

I am currently facing an issue with a site (a react app) deployed on GitHub pages. The site features cards that, when clicked on, should open a modal/dialog box. Ideally, clicking on the modal should close it. However, I have encountered a problem specific ...

Attempting to modify the key values within an object, however, it is mistakenly doubling the values instead

I'm encountering an issue when trying to update key values within an object. It seems to be adding duplicate values or combining all values together instead of assigning each name a specific language slug. I can't figure out where I'm going ...

PHP - WebCalendar - Show or Hide Field According to Selected Item in Dropdown List

Working with the WebCalendar app found at to make some personalized adjustments to how extra fields function. I've set up two additional fields: one is a dropdown list of counties, and the other is a text field. Within the dropdown list, there is an ...

What is the best way to extract a hashed password from my database using bcrypt encryption?

I am having trouble implementing bcrypt in my login post method. I have successfully stored encrypted passwords in the database during registration, but can't figure out how to compare them when users log in. Below is my register post method where th ...

Changing Images with Button Click in Javascript

I am facing an issue with my buttons that should swap images once clicked. The first two buttons work perfectly, but for the third and fourth buttons, the images do not disappear when clicking another button. Below is the current code in the document head ...

Tooltips remain inactive on the first plot until there is a change in the plot, triggering their functionality

I've encountered a strange issue with tooltips using d3-tip in a scatter plot. Initially, the tooltips are not functioning at all, and even the mouseover events are not triggering as expected. The scatter plot consists of three sets of data on each a ...

Implementing a JavaScript function to trigger the 'GET' method upon page load repeatedly

I am facing a strange issue where a javascript function is running multiple times upon page load (7 times in Chrome, 3 times in IE, 7 times in Firefox, 6 times in Opera, 4 times in Safari, and 4 times in Edge). What's going on??? Moreover, the xmlHtt ...

Tips for effectively managing the timeout of server-side AJAX calls1. Maxim

I'm currently developing server code in ASP.NET with the MVC framework. The client-side code is written in javascript. When sending an AJAX request from the browser to the server, whether using JQuery or not, timeouts can be set. Additionally, the br ...

Determine the success of an SQL query in Node.js

I've created a basic API using nodejs to connect my Flutter app with a SQL Server database, but I have a question. How can I verify if the query was successful in order to return different results? I'm attempting an update after a successful in ...

Is it possible to utilize the defineProperty accessor in JavaScript to modify the .length property of an array?

I am interested in setting an accessor on an array's length using Object.defineProperty() for academic purposes. This would allow me to notify for size changes dynamically. While I am familiar with ES6 object observe and watch.js, I prefer exploring ...

What could be causing the failure of this web component using shadow DOM when the HTML code includes multiple instances of the component?

Recently, a question was raised on this platform regarding the use of Selenium to access the shadow DOM. Curious about this topic, I delved into the MDN article Using shadow DOM and decided to replicate the code on my local machine. Surprisingly, it worked ...

Highlight text when the user is scrolling the page - using JQUERY

Can anyone suggest a way to dynamically underline text as the user scrolls down a webpage? The underline should only be visible while the user is scrolling. I've experimented with animate.css and other plugins, but haven't been able to achieve th ...