halfmoonui / halfmoon

Halfmoon is a highly customizable, drop-in Bootstrap replacement. It comes with three built-in core themes, with dark mode support for all themes and components.
https://www.gethalfmoon.com
MIT License
3.03k stars 118 forks source link

Close modal on form submit #81

Open Bruno-Marley opened 3 years ago

Bruno-Marley commented 3 years ago

I don't know if there is already a way to do this with this framework, but I have a button that opens a modal that contains a form and when I submit that form it was supposed to open on the same page but with the modal closed, but when I redirect on the backend when the page loads the modal is always open.

Is there anything I can do to make him close the modal whenever I submit the form?

opensaucerer commented 3 years ago

I had such issue also. Try redirecting as usual but change the internal link.

Let's say the original link when you open the modal is www.test.com/#modal-1

You can then redirect to something like www.test.com/#none

This will work normally without opening the modal again.

Note that #none should not be an id in your html

halfmoonui commented 3 years ago

Sorry for the late response, but are you using CSS modals or the ones that use JavaScript methods? In each case, you can do the following:

There is no built-in way to do this as of right now.

timbogdanov commented 2 years ago

@halfmoonui i have my modal in the root of the react project, when I try to toggle it, it does not toggle.

halfmoon.toggleModal('login-modal');

<div className="modal" id="login-modal" tabIndex="-1" role="dialog">

Any other solutions?