-
-
Notifications
You must be signed in to change notification settings - Fork 177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hiding in Modal-events breaks Modal #281
Comments
Give me a pen or fiddle so I can understand what you mean ;) |
I have the same problem; When trying to hide a openend modal, the backdrop is still active while the modal is not. |
@kolbma and @Vuurvlieg, what version of the library are you using? I had what I believe is the same problem on v2.0.19 but upgrading to v2.0.26 resolved the issue. |
@thednp @jhunschejones I am using the latest release, which is version 2.0.26. |
With this modified pen https://codepen.io/anon/pen/QPVPZo I've it always on the 2nd button click. Ah, and simply wait, don't close the modals with the mouse. Just open it with mouse. |
This seems to be the perfect test case to make it bulletproof. I will have a look at it asap. |
@Vuurvlieg @kolbma your examples are very very hard to make it work. It almost feels like an unfair challenge when in my mind this component was meant to be a good alternative to the original jQuery plugin with light and fast code execution. In the long run this would eventually get fixed as I know something like a I will try and find more time and investigate this issue, but I will need your help in testing and validating the proposed code changed to come. |
Some previous versions ago this bug did not occur. I think this bug was introduced in
No problem. Just let me know when you are ready and I will test as much as needed. |
Currently working on something that seems to make sense. |
@Vuurvlieg @kolbma @jhunschejones and anyone else, please test the latest master with your hardest test and let me know how it goes asap. Keep in mind:
UPDATE: As for your example, this is a tweak for your example scripting let modal = document.getElementById('modal1');
var opened = new Modal(modal, {backdrop: 'static', keyboard: false});
let timer = null;
function openModal1(el, ev) {
ev.preventDefault();
let modalHtml = modal.innerHTML;
var initModal = (() => {
modal.innerHTML = modalHtml.replace('Modal closed', 'Modal opened');
});
var resetModal = (() => {
modal.innerHTML = modalHtml;
});
modal.addEventListener('shown.bs.modal', function() {
clearTimeout(timer);
timer = setTimeout(function() {
modal.Modal.hide();
console.log('.hide() at 2000ms');
}, 2000);
});
modal.addEventListener('shown.bs.modal', function() {
clearTimeout(timer);
timer = setTimeout(function() {
modal.Modal.hide();
console.log('.hide() at 3000ms');
}, 3000);
});
modal.addEventListener('shown.bs.modal', initModal, {once: true});
modal.addEventListener('hide.bs.modal', resetModal, {once: true});
opened.show();
} Note:
|
@thednp Please dont close this issue as its not fixed yet. I'd love to test your solution but unfortunately I ran into a new issue, which is a HTML form can not be submitted inside a Modal. Before |
It was closed automatically as referenced in my commit. |
Let's take this step by step. First I need to know if our original issue is fixed. Then we can handle the new one ok? |
@Vuurvlieg solved, check master code. |
@thednp Thanks, submitting the form does work again! So I've tested your solution from #281 (comment) and it seems to work for the example given by @kolbma. However, it does not work for the codepen example given by me earlier. Once I open a second model when the first modal is still openend, the backdrop is being removed completely. Im not sure but my suggestion is to get rid of all SetTimeOut events and implement the transitionend_event functions. So I mean, when the Modal uses (fade) animation, the bootstrap events such as Let me clarify this by some code. (Again I'm not sure if this ever would work but it might be a solution to put inside the core of the Bootstrap native Modal component with some tweaking)
|
@Vuurvlieg why use a native script as if it's jQuery? Why initialize modal on button click? Why add even more event handlers on every click? You are creating more and more memory addresses, meaning you use more memory, you mess up the component private constants and variables, you are constantly bloating the DOM with new handlers (yes you set to On the question to why not add The main difference with the original plugin is that many of the constants/variables and methods that are public in the original version are made private with our version, to make the best possible GC work. The major drawback of our implementation is that it won't allow us to do jQuery style init/access/re-innit without any performance penalty or code breaks. So. Why not initialize modal, attach events, whatever, all before outside the click handler to only do the Try and brake this re-written example in less than 100 clicks. |
I'm sorry but I do not agree with this. Indeed I do use Anyway, the only 2 problems I have right now with the latest master is that the Also closing the second modal results in opening the first modal. Check this example. |
I put a lot of effort in solving this, tried everything I know, even if it doesn't affect me or a larger portion of the community, I was expecting you would confirm. As I said, this library doesn't do jQuery, it doesn't replace original library functionality word for word, if you want to use it, you use it the way I show you working on my modified version of your example because unfortunately I don't have anything else to help you. Meanwhile I'm going to close this until we have a solution or at least someone else struggling with the same situation. |
For the missing backdrop there is a very easy fix. Inside the
Working example, adjustment is done in JS at line #1244 |
Will check that asap. |
That's not a good resolution for some reasons:
I suggest you fork the project and use your "fix". |
Well, then you should test it again carefully because the showcase doesn't work either. Same problem at other level. I digged into the core code and its very logical that the backdrop is not shown. Its all about the timeouts with its intervals: When a second modal is being opened while the first one is already open, the current code executes the Simply adding a |
@kolbma is your original issue solved in the master please? |
@kolbma and @Vuurvlieg I've updated the wiki in regards to this issue. |
I'm getting this issue too. |
@tamb what is your use case? |
There is some problem when calling
Modal.hide()
in the event-listener at least forshown.bs.modal
and the Modal is already hidden.Without the workaround with
overwritten
and the additional event listener forhide.bs.modal
, at the nextModal.show()
, the dialog shows up very short and will disappear immediately and the body-class stays set. So the UI is broken, because half of the Modal is left and you can not close the Modal anymore.This happens when the
Modal
got hidden by some other call (e.g. escape key) before and the timeout-function is running and callingModal.hide()
afterwards.There are no JS errors in console.
I've no tested if the problem is with hiding a hidden Modal or with the timeout-event or both in combination.
The text was updated successfully, but these errors were encountered: