1

I'm trying to use a Bootstrap (v5.3.3) popover to display a basic search form.

Here's the HTML:

<li class="nav-item"><a id="searchLink" class="nav-link" data-bs-toggle="popover" data-bs-placement="bottom" data-bs-html="true" data-bs-content='<form><input class="form-control" type="text" name="search" /></form>'><i class="fa-solid fa-magnifying-glass"></i></a></li>

And here's the javascript:

const popoverTriggerList = document.querySelectorAll('[data-bs-toggle="popover"]');
const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstrap.Popover(popoverTriggerEl));

Is there a reason why the form won't display? The popover is blank. But if I replace it with basic HTML tags and text -- it works properly.

Or should I be using a different method to display a popup search form in Bootstrap? I don't want it to display in a modal.

2 Answers 2

0

Without more information/context it is hard to diagnose what is going on. From the top of my head, two things might be happening:

  1. Is your popovers ever triggered? I see many attributes but no trigger for the popovers to fire.
  2. Is the popover generation code in a document-ready function? If not it could be rendering before the DOM is loaded.
  3. (experimental) What happens if you put some plain text into the popover content?

Hope this helps!

Sign up to request clarification or add additional context in comments.

1 Comment

1. Yes. The popover displays -- but it's blank. No form/input field. 2. Everything I'm doing is in the two snippets above. 3. Plain text -- even with HTML tags -- will display.
0

Got it worked out. Ending up needing to add the sanitize: true parameter since HTML is included in the content.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.