Bootstrap select menu validation functions correctly on Firefox, however encounters issues on Chrome

I'm currently tackling a project involving HTML forms and utilizing Bootstrap for form validation. However, I've encountered an issue. After adding a select menu to the form and testing the form validation, I noticed that the other input fields displayed the validation styles on the select menu in Firefox only, not in Chrome or Edge. You can see the screenshots below:

Firefox:

https://i.sstatic.net/dLatv.png

Chrome:

https://i.sstatic.net/dllaW.png

The images clearly illustrate that the select menu validation only functions properly in Firefox but not in Chrome. Below is a snippet of the code: (Try running the snippet in Firefox)

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet">

<div class="container">
    <div class="row">
        <div class="col-lg-7 mx-auto mt-5">
            <form action="?" method="POST" class="was-validated" novalidate="">
                <div class="form-group">
                    <select name="mySelect" class="custom-select" required="">
                        <option disabled="" selected="" hidden="">Choose</option>
                        <option value="1">Option 1</option>
                        <option value="2">Option 2</option>
                    </select>
                    <p class="invalid-feedback">You must choose an option</p>
                    <button type="submit" class="btn btn-primary mt-3">Submit</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>

Therefore, my inquiries are:

  1. Is there a way to make Bootstrap select validation function for Chrome as well?
  2. Am I overlooking something here?

Answer №1

It is important to include the value attribute to avoid errors when using Chrome, as it detects an empty string in the value field and considers it a valid input. In order to ensure compatibility with Chrome, use the value attribute without specifying a value.

When implementing form validation, remember to use required instead of required=''. Although there is no issue with using required='', it is recommended to stick with required for consistency.

<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>

<div class="container">
    <div class="row">
        <div class="col-lg-7 mx-auto mt-5">
            <form action="?" method="POST" class="was-validated" novalidate>
                <div class="form-group">
                    <select name="mySelect" class="custom-select" required>
                        <option disabled selected hidden value>Choose</option>
                        <option value="1">Option 1</option>
                        <option value="2">Option 2</option>
                    </select>
                    <p class="invalid-feedback">You must choose an option</p>
                    <button type="submit" class="btn btn-primary mt-3">Submit</button>
                </div>
            </form>
        </div>
    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.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

What is the best way to align the main navigation at the center of

Even though I have utilized text-align: center, the style of .main-nav did not change. What is the most effective way to center this navigation menu? /***** Navigation *****/ .main-nav { font-family: 'Lato', Helvetica, Arial, sans-serif; f ...

Learn how to create sticky elements using jQuery or JavaScript with this helpful tutorial

I am currently searching for a useful tutorial or code snippet that demonstrates how to create a popular effect seen frequently on websites. This particular effect involves an element sticking to the top of the window when it reaches a certain point while ...

Creating a foundational design with Bootstrap 5, featuring a sidebar that scrolls seamlessly and a stunning fixed

I'm having some trouble figuring out the layout for a webapp I want to develop. LAYOUT IMAGE What I envision is a sidebar menu on the "S" section that can be scrolled independently, and a large image on the "I" section that changes based on th ...

Looking for some assistance with an auto-calculation form, anyone able to help out

Is there anyone skilled in JavaScript here? I am looking for a form that includes the following fields which will automatically calculate and display the total amount as I input numbers into the fields. <input type="text" name="actualprice" value=""&g ...

What is the process for adding data to a bootstrap table using code?

Struggling with adding data to a bootstrap table. The code is too complicated to get the table to display correctly! I've attempted various methods to insert the data into the table, but nothing seems to be working! Here is the original bootstrap ta ...

Searching for elements in Selenium using Python without a specified name

Looking for some assistance here. I'm trying to use Selenium to access a search field, but it doesn't have a name or ID in the html code. How can I locate and interact with this search field using Selenium? View the HTML code snippet for the sea ...

Is it recommended to continue using vendor prefixes for border-radius property?

When coding, I currently utilize the following: -webkit-border-radius: 4px; -moz-border-radius: 4px; border-radius: 4px; After running tests, it seems that there was no noticeable difference in modern browsers (Chrome 33+, Opera 25+, Safari 8+). Internet ...

Tips for effectively passing a parameter in @url.Action

I stumbled upon this piece of code: <button type="button" class="btn btn-inverse btn-danger" onclick="@("window.location.href='" + @Url.Action("ActionName", "ControllerName") +"'");"> Link </button> for redirecting- it works gre ...

Encasing words within a cell of a table

My goal is to ensure that the table width remains fixed and unaffected by long text strings. Even though I have PHP code in place to limit characters at 100 per cell, I want to guarantee that a lengthy text string will never expand the table beyond its set ...

When you open the link in a new tab, the form submission does not occur

I am currently working on a form that includes a JavaScript submit function. Within the form, there are 3 anchor tags that I want to use to set different values to a hidden parameter when submitted based on the link clicked. Although the form submission w ...

Challenges encountered with Emotion (Styled Components) integration in Gatsby

I rely on Emotion for creating styled components in my projects, but I have encountered some issues. This is how I initially install it: npm i @emotion/react @emotion/styled gatsby-plugin-emotion For instance, when integrating it into the Header component ...

Stylish CSS round link positioned on a half-circle

As a beginner in web design, I'm struggling with CSS. However, I have been given the task of creating a button like the one shown below. I am unsure of how to create a circular link like this. Any assistance would be greatly appreciated. ...

Inserting text underneath an image within a numbered list using HTML

I am attempting to achieve a specific layout where I have images in a list with text placed directly below each image. However, my attempts using <figure> and <figcaption> have not been successful. Below is the HTML code for my list: <div ...

Using Angular, you can effortlessly inject elements into the editable div from any location on the page

Currently, I am working on developing an HTML interface that allows users to input text and send it as a notification to our mobile application. However, I am encountering challenges with the text and dynamically inserted elements using Angular 5; The te ...

Challenges with styling <input> elements and autofill functionality

I am currently working on a login modal and have encountered an issue with styling input tags for browser autocomplete. Despite my efforts to reset the User Agent Stylesheet styling, the old styling reappears whenever autocomplete is triggered. Below is a ...

Using Bootstrap to create a fixed footer in Laravel

I have a Laravel project with Bootstrap added as the CSS. I have tried everything to make my sticky footer work, but when the page is longer than the window, it remains at the bottom of the window when scrolled up. Here is my main: <html> <head& ...

Tips for configuring a Vue component as the background

I am working on a Vue component that utilizes the tsparticles library. I want to set it as a background because it is covering all my other components. Can someone provide guidance on how to achieve this? Thanks! ...

How to center align your application in the desktop using Ionic framework

Query: How can I ensure that my ionic mobile application renders in the center of the screen when viewed on a desktop browser? Attempt 1: I experimented with using a wrapper div with a fixed width, such as max-width:732px; and margin: 0 auto;, however Ion ...

Ways to invoke a jQuery plugin method from outside the plugin script

I have the following script code (function($) { $.fn.youamaAjaxLogin = function(options) { function start() { //start } .... Is there a way to call the start() function from outside? (func ...

Issue with background image not covering entire div

I am experiencing an issue where the background image of a div element is not occupying the full image. I want to display images side by side with text underneath them. Below is the CSS code: .img-w { position: relative; background-size: cover; ba ...