I need to open a modal after a submit occurs on a particular button, I wanted to know if there is an event for it, something like post submit.
I need to open a modal after a submit occurs on a particular button, I wanted to know if there is an event for it, something like post submit.
Apparently you're using jQuery, so just use event.preventDefault ()
something like
$('#meuform').on('submit', function(event){
event.preventDefault();
//abre a modal aqui
});
This will prevent the action default
of the event, in this case, send ( submit
) of the form, and will allow to open its modal.
As a side effect the sending of the data will have to be done via ajax.
There is a "gambiarra" that depending on what you need can work. It consists of giving return false
instead of using preventDefault()
, usually used to do some kind of validation via js before sending.
$('#meuform').on('submit', function(event){
if(!validaForm()){
//abre a modal aqui
return false;
}
});
One option is to prevent the page from being reloaded using event.preventDefault
:
$( "#form" ).submit(function( event ) {
event.preventDefault();
$( "#dialog" ).show();
});