How to prevent a modal to close in the End of an Action?

Hello. Inside my modal, I have a button to save the details of a sub-action. I am using a button to save details because I need to save, for example, some costs associated to that sub-action, and it´s a way to get the Id from the sub-action, and then pass it to the costs_subaction table.

So I enclosed the costs form inside an if, and it only shows the costs, if the details from the sub action are corret. I created a boolean to define when to show the costs, and I´m making it true when saving the sub-action details. 

Now, the problem is that since the action has an end, it closes the modal before I get to insert the costs.

Here is the action from that button.

Maybe this is not the best way to do waht I need, but its the only one I know...

Sorry for the basic questions.

Could really use some help.

Thanks :)


look to this post, I think that it's helps you.


Thanks for the quick answer.

SyntaxEditor Code Snippet

setTimeout(function(){ $ModalSubacao.unbind(GuardarSubacao); }, 5);

I wrote this but I dont think its correct...