bootstrap modal prevent closing when another one opens - bootstrap-modal

Prevent closing of modal when another modal opens when both modal are set to static backdrop. i have tried using data-bs-backdrop="static" and data-bs-keyboard="false" but doesn't works but works when one is not set to static.

Related

Bootstrap Modal close button does not close the modal

I am using the pypi.org boostrap modal as explain in the site. Everything work fines fine as expected but the problem is when I click a button for eg addFoo button and I decided to close the modal using either the close button or X button the modal does not close.

open a dialog behind a modal dialog or after it is closed

I have an application which has several background tasks running in non-GUI threads which may time to time require some user interaction so they send signal to the main thread and the corresponding slot creates a dialog and shows it to the user. Meanwhile the task thread is waiting in a blocking event loop. Once the user answers the dialog and closes it, the task event loop is signaled to quit and the task resumes.
There is however a problem. In the GUI thread I can still use the application which time to time shows some modal dialogs. When there is a modal dialog already shown and then the background tasks requests another dialog to be opened, this task-related dialog is displayed in front of the modal dialog. But this new dialog is not modal and the modal dialog is hidden behind it. The non-modal one therefore is not responsive, the application feels like it got stuck.
My idea was to display the new dialog always behind the modal dialog, which I believe I can get with QApplication::activeModalWidget(). But I do not know how to do this. How can I show a dialog behind another dialog but still in front of the main window (which is a parent of both dialogs)? I tried to call QApplication::activeModalWidget()->activateWindow() after I show the non-modal one but his causes blinking of windows and moreover I can still click into the new non-modal dialog hiding the modal one. So this is not a perfect solution.
Or do you see any other solution?
Maybe I could implement a queue of dialogs, and once there is any modal dialog visible, then the new background task-related dialog would not be shown, only enqueued and shown once the modal dialog is closed. However this feels more fragile solution to me.
Any ideas?
UPDATE: I redefined the question by adding "or after it is closed" becasue this works for me too.
I found a solution which seems to work well and which shows the non-modal dialog only after the modal dialog is closed.
QWidget *nonModalDialog = ... // creates the non-modal dialog
nonModalDialog->setAttribute(Qt::WA_DeleteOnClose);
QWidget *modalDialog = qApp->activeModalWidget();
if (modalDialog == nullptr)
{
// no modal dialog, we can show the non-modal one now
dialog->show();
}
else
{
// we must wait until the modal one is closed
QObject::connect(modalDialog, &QWidget::destroyed, nonModalDialog, &QWidget::show);
}
This seems simple and robust.
I think you are looking for QWidget::raise(). You should be able to use QApplication::activeModalWidget()->raise() after calling dialog->show() on your non-modal dialog.
If you're getting into situations where you have multiple modal and non-modal dialogs, all launched in different order, this might not be enough to solve the problem. You might raise one modal dialog only to have others behind other non-modal dialogs and end up stuck again. You should consider keeping a reference to the collection of modal dialogs that are currently active so that you can make sure they are always on top of the non-modal dialogs.

Zurb Foundation 6 - Reveal modal won't reopen after close

I am using a reveal modal and populating it using AJAX, following the recommended methods in the Zurb Documentation to do so. The modal appears and populates OK, but if I then close the modal (e.g. click on background) and try to reopen I get a javascript error. I am trying to fix this so I can reopen the modal after close.
I have tried adding the option "data-reset-on-close" to the modal definition to ensure that the modal is reset when it closes, but this does not help.
Here is how the modal itself is defined.
<div class="reveal" id="edit_modal" data-reveal data-reset-on-close="true">
Here is the javascript I am using to trigger the modal (and load the javascript. The modal fires when I click on a <div> with ID "load_modal".
$("#load_modal").click(function() {
var $modal = $('#edit_modal');
$.ajax("/_modal_content/edit_modal")
.done(function(resp){
$modal.html(resp).foundation('open');
});
});
The aim is to allow the user to close then reopen the modal as required. Right now it opens once without problem, but it will not open a second time.
On attempting to open the second time a javascript error is reported:
app.js:65 Uncaught TypeError: t.html(...).foundation is not a function
at Object.<anonymous> (app.js:65)
at l (<anonymous>:3:6477)
at Object.fireWith [as resolveWith] (<anonymous>:3:7245)
at r (<anonymous>:4:10371)
at XMLHttpRequest.<anonymous> (<anonymous>:4:16224)
Hopefully I'm doing something silly and there is an easy fix.
Would be most grateful for any guidance on what I should do to resolve.
There are some tutorials on this that may help:
https://zurb.com/university/lessons/dynamically-update-your-web-pages
and
https://zurb.com/university/lessons/ajaxing-dynamic-content-with-foundation

How to load modal when button from another modal is clicked

I have a modal and in that modal is a button. I want to load another modal when the button is clicked. How am I going to do it. I actually set data-toggle but when I clicked the button, the modal is loaded but cannot be seen. It can only be seen when I closed the parent modal.
You must also dismiss the previous modal with data-dismiss="modal".
Modal 2

How to hide a modal dialogbox in MFC application?

I have a hard time hiding a modal dialog box. What I am doing is - I am trying to design a UI for my own application in MFC, kind of a setup assistant.
In the 1st dialog box I have NEXT button, so when I click that it has to hide the 1st dialog box and move on to the 2nd dialog box, where I have some controls in 2nd dialog box.
How can I achieve that?
I have never tried to hide a Modal dialog...not sure how it can be done.
Anyway, it seems to me you don't need to hide the dialog but destroy the first one and create the second one. You can use EndDialog to terminate a modal dialog.
But MFC has its own mechanism to create your own wizard, have a look at this class CPropertySheet. I am sure you can find thousand of examples, this is one.
Hope it helps.
You can use ShowWindow() function to hide modal
Its default patametet is SW_SHOW which is equal true value 1 and
To hide modal use SW_HIDE value when you click next button
You just use ShowWindow(SW_HIDE) If you make prev button you should use modal pointer
Or next modal should child modal because you cannot have prev modal variable.
I wish you understand me for my english