Bootstrap modal not replacing content for different link - twitter-bootstrap-3

I have successfully added a modal from external link in my web-app, but now when I click the button to launch the modal the content of the previous modal is launched. I want it to be reloaded every time.
This is the button for launching the modal.
<button href="/forum/flag_post/0838024b-f210-4f4d-ac53-fd4ade12d533" class="btn btn-default" data-toggle="modal" data-target="#myModal">Report</button>
There are mutliple buttons like this and each one has a different href and once I press a button and close the modal, the same modal content is lauched every button. I don't want that. I want the modal content to be loaded freshly from the URL.
This is the modal class:
<!-- Modal HTML -->
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<!-- Content will be loaded here from "remote.php" file -->
</div>
</div>
</div>

Use JQuery:
<script>
$(document).ready(function(){
$("#modalLinks a").click(function () {
var addressValue = $(this).attr("href");
$(".modalContent").load(addressValue);
});
});
<script>
<div id="modalLinks">
Report
Somewhere
Somewhere too far
</div>
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>
The idea is whenever you click on a link, JQuery update the modal content with ajax.

Related

Make bootstrap 5 dropdown menu fully visible in a scrollable modal body

I have a dropdown inside a fixed height and scrollable modal body. The height of dropdown menu exceeds the modal body. When dropdown is open, it will cause the body scroll. How can I make the dropdown menu fully visible?
Here is jsfiddle
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">
Modal Title
</h4>
</div>
<div class="modal-body bg-secondary" style="height:15rem; overflow-y:auto;">
<div class="alert alert-info">
Modal body is fixed height and scrollable. Want to make dropdown menu fully visible.
</div>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown">
Dropdown
</button>
<div class="dropdown-menu">
<div class="p-3" style="width:10rem;height:12rem;">
Dropdown Content
</div>
</div>
</div>
</div>
</div>
This should work:
const dropdown = document.querySelector('.dropdown');
const dropdownMenu = document.querySelector('.dropdown-menu');
dropdown.addEventListener('shown.bs.dropdown', () => {
window.requestAnimationFrame(()=>{
dropdownMenu.scrollIntoView({
behavior: "smooth",
block: "end",
inline: "nearest"
});
});
});

How to create a non interruptive bootstrap modal?

I have a small modal that appears at the top of the screen periodically. When it appears it blocks typing in inputs and scrolling until it goes away. Is there a way to make the modal non-interruptive so that when it appears it doesn't cause focus change or anything else. I want it to be minimally invasive.
Below is my modal:
<div id="myModal1" class="modal fade" tabindex="-1" role="dialog" style="margin-top:10px;" data-backdrop="false">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
Hello World
</div>
</div>
</div>
</div>
If you want a non-interruptive modal, why not use an alert?
https://getbootstrap.com/docs/3.3/components/#alerts
A modal interrupts the user by definition.

Four divs for one box - can I remove some?

Can I eliminate some of these divs. I like to keep my code lean. I understand the 5th one b.c. it is the footer, but what about the other 4.
Here is the code
<div class="container">
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Submit</button>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-body">
<p>Bookmarks</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Here is the fiddle to run it
https://jsfiddle.net/te4ta7hc/
Let me tell you about the modal window first
Where the modal content is the base which will show after triggering the modal.
Modal Header where we can able to put the heading for our modal window like( Enquiry form).
Modal Body: where the actual content have to be present whatever it may be. Such as Forms, Text contents etc..
Modal footer: where you can add some actions like close button or anything else
So if you want to eliminate the code means you can remove the modal header and footer.. make sure you added button to close modal in modal body

how to auto focus a input in a modal window

i'm using angular2 but this modal I did it with bootstrap3. I have the following input in the modal windows
<img id='searchIcon' src="images/search.png" data-toggle="modal" data-target="#myModal">
<div id="myModal" class="modal fade modal-container" role="dialog">
<h1>search</h1>
<input [focus]='true' id='inputSearch' type="text">
</div>
and I would like when I open the modal window to have the input focused (kind of is in pluralsight.com when you click on the magnifier icon).
As you see I tried [focus]='true'but didn't work
This will do
$('#myModal').on('shown.bs.modal', function() {
$("#inputSearch").focus();
});
I believe all you need to do is add autofocus to your input tag like this.
<img id='searchIcon' src="images/search.png" data-toggle="modal" data-target="#myModal">
<div id="myModal" class="modal fade modal-container" role="dialog">
<h1>search</h1>
<input id='inputSearch' type="text" autofocus>
</div>

How to do transclusion in vue.js?

I'm trying to make a bootstrap modal component with the awesome vue.js, but I haven't been able to find a good way to transclude- that is, I want to bundle several nested elements containing the backdrop, modal window, close button, etc. into one component. This component will then need to wrap the markup placed inside of it.
The component
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
// transcluded content goes here.
</div>
</div>
</div>
The content
<bs-modal>
<h1>Some title lol</h1>
<p>The content 'n stuff</h1>
</bs-modal>
Transcluded
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<h1>Some title lol</h1>
<p>The content 'n stuff</h1>
</div>
</div>
</div>
Ah, found it.
http://vuejs.org/guide/components.html#Content_Distribution_with_Slots
You use a special <slot></slot> element to indicate where to transclude.
So,
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<slot></slot>
</div>
</div>
</div>