Sleek Dialog Boxes with Bootstrap 4 - Bootbox Modal

Within the structure of my webpage, there resides a table containing various elements. One specific cell within this table holds a link that triggers jQuery scripts upon being clicked. An example action initiated by clicking this link is displaying a Bootstrap Dialog box, which can conveniently be achieved using Bootbox.js. Nevertheless, it should be noted that Bootbox does not currently offer support for Bootstrap 4.

Initially, encountering an issue where the bootbox dialog failed to display due to differences in class names between Bootstrap 3 and Bootstrap 4 was resolved. In Bootstrap 3, the class identifier used for showing elements was in, whereas in Bootstrap 4, it has been replaced with show. This discrepancy has already been addressed, but here is a representation of how the setup appears at present:

https://i.sstatic.net/1VyW7.png

The HTML structure generated through invocation of bootbox.js in this scenario is as follows:

<div tabindex="-1" class="bootbox modal fade show in" role="dialog" style="display: block;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button class="bootbox-close-button close" aria-hidden="true" type="button" data-dismiss="modal">×</button>
                <h4 class="modal-title">Test Title?</h4>
            </div>
            <div class="modal-body">
                <div class="bootbox-body">Test Message</div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" type="button" data-bb-handler="cancel"><i class="fa fa-times"></i> Cancel</button>
                <button class="btn btn-primary" type="button" data-bb-handler="confirm"><i class="fa fa-check"></i> Confirm</button>
            </div>
        </div>
    </div>
</div>

An obstacle present within the div section featuring the class name modal-header is the order in which the button precedes the h4 element. Simply flipping these positions would resolve the issue at hand, prompting the query on how this rearrangement could be accomplished through bootbox syntax. While temporarily omitting the title might provide a workaround until Bootbox integrates Bootstrap 4 compatibility, I am intrigued to explore potential solutions.

The current progress in addressing this dilemma is illustrated below:

                bootbox.confirm({
                    className: "show", // manual addition of class name
                    title: "Test Title?",
                    message: "Test Message",
                    buttons: {
                        cancel: {
                            label: "<i class='fa fa-times'></i> Cancel"
                        },
                        confirm: {
                            label: "<i class='fa fa-check'></i> Confirm"
                        }
                    },
                    callback: function (result) {
                        // custom callback function
                    }
                });

Answer №1

If you want to fix this issue, you can simply use CSS:

.bootbox .modal-header{
display: block;
}

Answer №2

solution is to use the following code:

.bootbox .modal-header {
    flex-direction: row-reverse;
}

Answer №3

To resolve this issue, simply switch the positions of the headline and the x in the HTML code like this:

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">

<div tabindex="-1" class="bootbox modal fade show in" role="dialog" style="display: block;">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Test Title?</h4>
                <button class="bootbox-close-button close" aria-hidden="true" type="button" data-dismiss="modal">×</button>
            </div>
            <div class="modal-body">
                <div class="bootbox-body">Test Message</div>
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" type="button" data-bb-handler="cancel"><i class="fa fa-times"></i> Cancel</button>
                <button class="btn btn-primary" type="button" data-bb-handler="confirm"><i class="fa fa-check"></i> Confirm</button>
            </div>
        </div>
    </div>
</div>

When looking for closeButton at this link: https://raw.githubusercontent.com/makeusabrew/bootbox/master/bootbox.js, it seems a bit hard-coded to me.

However, by changing

dialog.find(".modal-header").prepend(closeButton);

to:

dialog.find(".modal-header").append(closeButton);

within that file, the issue should be resolved.

EDIT:

Additionally, there is

dialog.find(".modal-title").html(options.title);

Therefore, you must append the closeButton to the title. This adjustment should make it work correctly as intended.

Answer №5

One potential solution is to rearrange the structure of the webpage within the bootbox callback function, for instance:

bootbox.confirm({
    ...
    callback: function () {
       $('.modal-header').prepend('.modal-title');                 
    }
});

Answer №6

My solution to the issue was simple and effective: Navigate to your JavaScript file (in my case, it's bootbox.min.js) and locate this particular line :

var m=b(n.closeButton);a.title?d.find(".modal-header").prepend(m)

Replace it with:

var m=b(n.closeButton);a.title?d.find(".modal-header").append(m)

By changing "prepend" to "append", you should see the close button move to the right side as expected.

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

One cannot focus on HTML if it's disabled

I am currently exploring options to prevent an input from receiving focus without disabling it entirely. I need the backend to still retrieve data, but I want to restrict user editing of the input fields at certain times. Disabling the input is not an opti ...

How to address additional attributes received from the server in Next.JS

Encountering an error while trying to render a canvas with specified height and width within a child component in a NextJs app. The issue arises when attempting to integrate this mouse effect into my NextJS application. Everything functions correctly until ...

Uploading a file to a .NET Framework API Controller using React

I am trying to figure out how to send files in the request body to an API controller in .NET framework using React. My goal is to achieve this without changing the request headers, so I want to send it as application/json. What I am looking for is somethi ...

Are there any methods to determine the way in which a user has absorbed the content of a post

This particular question sets itself apart from the one found here, as it aims to detect various user behaviors beyond just browser activity. Specifically, I am interested in identifying behaviors such as: Rapidly skimming through an article from start ...

Can an element contain two different classes at the same time?

Apologies if the title was unclear. I am trying to customize the color of my font awesome social media icons individually. Although I have successfully changed the color for all of them, that is not the desired outcome. Here is the icon: <i class=& ...

How can I adjust the font size of information retrieved from a JSON file using ng2-smart-table?

I recently tried using the following CSS code: :host /deep/ ng2-smart-table {font-size:22px;} However, despite implementing this code, I have not noticed any change in the font size. ...

Ways to effectively utilize jQuery objects as arguments in the delegate function

When working with delegate and multiple selectors, you can use the following syntax: $(contextElement).delegate('selector1, selector2' , 'eventName', function(){ //blabla }); In projects where managing DOM elements is important, stori ...

Unable to add new tags in Vue multiselect component

Currently, I am utilizing a Vue Multiselect instance with two functions. One function interacts with the database to provide autocomplete functionality, which is working successfully. The second function allows for adding new tags that are not present in t ...

Tips for inserting a concealed column in slickgrid

Can I keep a column hidden in slickgrid? In other words, is it possible to store information for each row without displaying it on the grid? ...

Potential Challenges and Considerations when Parsing Templates in vue.js

According to the Vue documentation on DOM Template Parsing Caveats: The documentation states that this limitation does not apply if you are utilizing string templates from specific sources: String templates (e.g. template: '...') v-for with a ...

I am still receiving an empty dropdown value despite implementing ng-selected

I am having issues with using ng-selected to retrieve the selected value from a dropdown. Instead of displaying the selected value, it appears blank. Here is the code snippet I have tried: <div> <select id="user_org" ng-model="selectedorg.all ...

Issue with Ajax call in WordPress not functioning via a plugin

Having trouble with my Ajax calls. The first one works fine, but when it sends data to send_data.php, I encounter issues running Wordpress functions. After the data is sent to send_data.php, attempting to run a Wordpress function like add_post_meta(2, &ap ...

HashId plugin for Angular

Currently, I'm attempting to integrate into my Angular project built on the latest version. After discovering this definition file: // Type definitions for Hashids.js 1.x // Project: https://github.com/ivanakimov/hashids.node.js // Definitions by: ...

Is using float:right making the jquery slide toggle dropdown div (triggered by hover) appear glitchy?

Utilizing jQuery's slidetoggle and hover functions, I have successfully implemented a dropdown feature in my div. Within this div, there is various information displayed including the date, a note counter, and three buttons. The first two are Tumblr ...

CSS parsing through regular expressions

I trust this message finds you in good health. I understand that a one-size-fits-all regular expression for CSS may not work in every scenario. However, I am currently analyzing a specific CSS segment and can customize the expression to meet my requiremen ...

Creating consistency in tab spacing within a text area

At the moment, I am utilizing an HTML textarea attribute to collect input from users and then displaying that text back to them formatted. However, there seems to be an issue with how it handles tabs. For instance, when attempting to input the following: ...

Unable to retrieve / in Node.js

I am currently in the process of creating a simple webpage consisting of 2 HTML files and an index.js file. The webpage is being developed using Node.js and Express for routing purposes. Everything appears to be functioning correctly until I try to access ...

The jQuery form validation feature surprisingly doesn't take into account the value of the submit button

I have implemented jQuery form validation from Here is an example from demo.html <form id="form-signup_v1" name="form-signup_v1" method="get" class="validation-form-container"> <div class="field"> <label for="signup_v1-username">Fir ...

send the value of a variable from a child component to its parent

I have created a typeahead component within a form component and I am trying to pass the value of the v-model from the child component to its parent. Specifically, I want to take the query model from the typeahead component and place it in the company mode ...

``There seems to be an issue with the functionality of the href link

Currently, I am utilizing purecss to design colorful buttons on my website. However, I am encountering an issue where the href link is not clickable even though the button displays correctly. <button class='pure-u-1 pure-button pure-button-primary ...