Popover with Bootstrap 4 input field

The issue is outlined in the title. I am facing a problem where an input field loses focus within a Bootstrap 4 modal and popover setup, specifically in Firefox but not in IE 11.

Popover:

$('[data-toggle="popover"]').popover({
        container: "body",
        sanitize: false,
        content: function () {
            return $("#choose-user-popover-content").html();
        }
    }).on('shown.bs.popover', function () {
        $('#ExecutorSNPSearchStr').focus();
    });
    

Popover content HTML:

<div id="choose-user-popover-content" style="display: none;">
    <div class="row">
        <div class="col">
            <div class="input-group">
                <input type="text" class="form-control" id="ExecutorSNPSearchStr" aria-describedby="ExecutorSNPSearchStrAddon"/>
                <div class="input-group-append" id="ExecutorSNPSearchStrAddon">
                    <button class="btn btn-sm btn-outline-info w-3" type="button">
                        <i class="fas fa-search"></i>
                    </button>
                    <button class="btn btn-sm btn-outline-danger w-3" type="button">
                        <i class="fas fa-trash-alt"></i>
                    </button>
                </div>
            </div>
        </div>
    </div>
    

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

Could someone provide insight into what might be causing this issue and suggest possible solutions?

UPD: I have replicated the scenario in a separate HTML file.

$(function () {
                    $('[data-toggle="popover"]').popover({
                    sanitize: false,
                    content: function () {
                    return $("#PopoverContent").html();
                    }
                    });
                }).on('shown.bs.popover', function () {
                    $('#ExecutorSNPSearchStr').focus();
                });
Your additional code here...

Answer №1

You've made a minor mistake by including tabindex="-1" in your modal, causing the input focus to be removed.


Bootstrap 4 Solution

MODAL + INPUT POPOVER

$(function () {
  $('[data-toggle="popover"]').popover({
      container: 'body',
      title: 'Search',
      html: true,
      placement: 'bottom',
      sanitize: false,
      content: function () {
          return $("#PopoverContent").html();
      }
  });
})
... (content continues with Bootstrap 4 implementation)

INPUT POPOVER + INSIDE CONTENT

$(function () {
    $('[data-toggle="popover"]').popover({
    container: 'body',
    html: true,
    placement: 'bottom',
    sanitize: false,
    content: 
    `<div id="PopoverContent">
      <div class="input-group">
        <input type="text" class="form-control" placeholder="Recipient's username"
             aria-label="Recipient's username with two button addons" aria-describedby="button-addon1">
        ... (content truncated for brevity)
    </div>`
    })
});
... (content continues with Bootstrap 4 implementation)

INPUT POPOVER + OUTSIDE CONTENT

$(function () {
    $('[data-toggle="popover"]').popover({
    container: 'body',
    html: true,
    placement: 'bottom',
    sanitize: false,
    content: function() {
        return $('#PopoverContent').html()
    }
    })
});
... (content continues with Bootstrap 4 implementation)


Bootstrap 5 Implementation

MODAL + INPUT POPOVER

const popover = new bootstrap.Popover(document.querySelector('.callPopover'), {
    container: 'body',
    title: 'Search',
    html: true,
    placement: 'bottom',
    sanitize: false,
    content() {
        return document.querySelector('#PopoverContent').innerHTML;
    }
})
... (content continues with Bootstrap 5 implementation)

INPUT POPOVER + INSIDE CONTENT

const popover = new bootstrap.Popover(document.querySelector('[data-toggle="popover"]'), {
    container: 'body',
    title: 'Search',
    html: true,
    placement: 'bottom',
    sanitize: false,
    content: `<div id="PopoverContent">
      <div class="input-group">
        <input type="text" class="form-control" placeholder="Recipient's username"
             aria-label="Recipient's username with two button addons" aria-describedby="button-addon1">
        ... (content truncated for brevity)
})
... (content continues with Bootstrap 5 implementation)

INPUT POPOVER + OUTSIDE CONTENT

const popover = new bootstrap.Popover(document.querySelector('.callPopover'), {
    container: 'body',
    title: 'Search',
    html: true,
    placement: 'bottom',
    sanitize: false,
    content() {
        return document.querySelector('#PopoverContent').innerHTML;
    }
})
... (content continues with Bootstrap 5 implementation)

Answer №2

Just wanted to add some thoughts, check out https://github.com/twbs/bootstrap/issues/36692#issuecomment-1178261690

To summarize, newer versions of Bootstrap are stricter about maintaining focus within modals. When there is a popover inside the modal, it creates its own container outside the modal which may make it inaccessible due to focus restrictions. One workaround is to specify the popover's container to be the modal itself (or a specific container within the modal) instead of the default "body".

Answer №3

Arriving a bit late to this discussion, I've encountered the same issue while working with Bootstrap 5.

After copying the Bootstrap 5 code solution into my files, everything functioned correctly.

Subsequently, I adjusted the HTML to incorporate a simplified version of my modal (excluding tabindex=1) and popover, which still worked flawlessly.

However, upon substituting the link to the beta edition of Bootstrap 5 with a link to the most recent full release, the initial problem resurfaced - rendering it impossible to input anything into the popover field.

Below, you'll find my code in case someone can identify an error, but it certainly seems like a bug within Bootstrap 5.

<!DOCTYPE html>
<html>

<head>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea8885859e999e988b9aaadfc4dbc4d9">[email protected]</a>/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css">
</head>

...

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

Aligning form elements vertically in the center using Bootstrap 4

I am struggling to center the content of my entire page both horizontally and vertically. Despite following the guide on Bootstrap 4 beta's official website, I can't seem to get it right - https://getbootstrap.com/docs/4.0/layout/grid/ htm ...

Issue with React-Redux state not updating properly in setInterval()

I am encountering an issue with react-redux / react-toolkit. My state is called todos and it is populated with 3 items correctly, as shown in this image: https://i.sstatic.net/LThi7.png Below is the code of my todo slice: import { createSlice } from &apo ...

Angularjs - How come I am able to modify an object but not the list (ng-repeat) from a separate view?

After updating the customers object in the console, I noticed that the list (ng-repeat) is not reflecting the changes. What should I do? Interestingly, it works fine when I implement this function and view2.htm's HTML inside page.htm. HTML "page.htm" ...

What is the best way to search for and isolate an array object within an array of objects using Javascript?

I am attempting to narrow down the list based on offerings const questions = [ { "id": 2616, "offerings": [{"code": "AA"},{"code": "AB"}]}, { "id": 1505, "offerings": [ ...

Creating a merged object from a split string array in TypeScript

I possess an array containing objects structured as follows; const arr1 = [ {"name": "System.Level" }, {"name": "System.Status" }, {"name": "System.Status:*" }, {"name": "System.Status:Rejected" }, {"name": "System.Status:Updated" } ] My object ...

Static Sidebar integrated with Twitter Bootstrap version 2.3.5

Currently, I am in the process of learning how to incorporate a fixed sidebar using Twitter Bootstrap 2.3.5. Below is a snippet of the code I have been working on: <div class="container"> <div class="row"> <div class="span4" id="sid ...

Employ an asynchronous immediately-invoked function expression within the callback

Can an asynchronous IIFE be used inside the callback function to avoid the error message "Promise returned in function argument where a void return was expected"? You can find an example here. signIn(email: string, password: string, course?: ICourse): ...

Steps to Retrieve a Textbox Value Using Jquery/JavaScript When the ID is Dynamically Generated Depending on a Condition

Struggling with a jQuery function to retrieve the value of a text box upon clicking a button in multiple rows. Can't seem to get it to work, any suggestions? Thanks in Advance. Text-box Code:- $('input.R_Insert').click(function() { var ...

Is there a way to transform a basic XML document into JSON using jQuery without the need for external plugins?

Can someone help me with converting an xml document to json using jQuery without any plugins? I've been struggling to find the right code and steps to proceed. ...

Issues with Bootstrap-slider.js functionality

I'm having trouble getting the bootstrap-slider.js library from to function correctly. All I see are textboxes instead of the slider components. You can view an example at I have verified that the CSS and JS files are pointing to the correct direc ...

What is the process for adjusting the button color within Bootstrap?

Is it possible to customize the colors of Bootstrap buttons beyond the default options? I'd like to explore more color choices for my buttons. ...

Jquery fails to identify a specified ID when it is printed on the page

Having trouble manipulating the cells of a table using JQuery In my jsp file, I am calling another jsp file using JQuery/Post to dynamically print a table $(document).ready(function(){ var usuario = $("#Id").text(); var s = "13"; $.post ...

Issue arising in Angular 7 due to the binding between the TypeScript (ts) file and HTML file for the property [min]

I am currently utilizing Angular Cli version 7.3.9 In my project, I have implemented a date type input that is intended to display, in its datepicker, starting from the next day after the current date. This is how I approached it in my .ts file: debugger ...

ReactJs CSS - This file type requires a specific loader for processing. There are currently no loaders configured to handle this file

I've noticed that this issue has been raised multiple times before. Despite going through all the questions, I still can't seem to resolve it. The transition from Typescript to Javascript went smoothly until I reached the implementation of CSS. U ...

After clicking multiple times within the modal, the modal popup begins to shift towards the left side

I successfully implemented a modal popup in my project, but encountered an issue where the popup moves to the left side if clicked multiple times. Despite searching extensively online, I have not been able to find a solution to this problem. Below is the ...

Tips for traversing through jquery ui accordion when a single panel has been disabled

I currently have a jQuery UI accordion set up with Next and Previous buttons in each panel to navigate through the sections. Additionally, I have a select HTML element in one of the panels where I can choose an option. If Option 1 is selected, the second a ...

Display picture on webpage in 10 seconds

Hi, I'm working on a website project and I've run into an issue where I need to use JavaScript, but I haven't mastered it yet. I have a background image slideshow set up where a new image appears every 6 seconds. My idea is to have the sec ...

Halt dragging on the jQuery when the boundaries become visible

Check out this cool war game map at War game map I have designed a jQuery draggable div containing a map image, enclosed within a smaller div with overflow set to hidden. The main purpose is to allow users to drag the map around similar to maps.google.com ...

Encountered Runtime Issue of TypeError: undefined cannot be iterated (unable to access property Symbol(Symbol.iterator))

I've been working on a multiselect feature in my Next.js project, utilizing states and setting them accordingly. However, I keep encountering this specific error: https://i.stack.imgur.com/m8zuP.png whenever I click on this: https://i.stack.imgur.c ...

Tips for transferring values from one array to another array using JavaScript

I am attempting to incorporate values from the array below into another array [ {"criteriaName": "CRITERIA 1"}, {"criteriaType": "Dependent"}, {"table": "Table1"}, {"column": "Column1"}, {"joinType": "OR"}, {"o ...