Home > Software engineering >  Closing a modal only if the confirmation is accepted in Laravel
Closing a modal only if the confirmation is accepted in Laravel

Time:12-02

I am new to Laravel and I am trying to make a modal with a close and add button. When I click close, a small dialog shows to ask if you really want to quit the modal, but when I click ok, it does not close the modal. Does anyone know why this is?

My modal:

<div class="modal-footer">
          <button type="button" class="btn btn-secondary" onclick ="return confirm('Do you really want to quit?');" data-backdrop="static">Close</button>
          <button type="submit">Add</button>
        </div>

CodePudding user response:

return confirm('Do you really want to quit?'); doesn't do anything. You should use jQuery to hide the modal.

If you really want to use confirm, you could use the following in-line command or use a separate function.

Suppose the id of the modal is "test_modal", then:

<div class="modal-footer" id="test_modal">
    <button type="button" class="btn btn-secondary" 
            onclick ="confirm('Do you really want to quit?')? $('#test_modal').modal('hide') : false" 
            data-backdrop="static">Close</button>
    <button type="submit">Add</button>
</div>
  • Related