Don't dismiss modal on backdrop click


Topic: Don't dismiss modal on backdrop click

Ulises Ceca asked 6 years ago

Expected behavior I would like my modals not to be closed when it's clicked outside of it.

Actual behavior It closes when clicking outside.

Resources (screenshots, code snippets etc.)

No needed


Magdalena Dembna staff premium commented 6 years ago

Have you tried selecting backdrop with modal-backdrop class and preventing default behavior with .preventDefault?


TriSys commented 5 years ago

Your documentation at: https://mdbootstrap.com/docs/jquery/modals/basic/#via-JavaScript does not include your specified property. Where is this documented?


Magdalena Dembna staff premium commented 5 years ago

I have created a snippet with modal which is not closed on outside click: https://mdbootstrap.com/snippets/jquery/m-dembna/1199872 . Simply add data-backdrop="false" to your div with modal class. Kind regards, Magdalena


TriSys answered 5 years ago

Thanks for your efforts, but this is not quite what I am asking. I see you added data-backdrop="false", and whilst this does indeed prevent the popup from being closed, I really need access to a button in the popup where I can get the onclick event in Javascript, and then close this modal in code. So you have a sample of this please?


Magdalena Dembna staff premium commented 5 years ago

I modified the previous example to include a closing button. Take a look and let me know if it's helpful. Kind regards, Magdalena https://mdbootstrap.com/snippets/jquery/m-dembna/1199872


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.8.0
  • Device: PC
  • Browser: Chrome
  • OS: Ubuntu 18
  • Provided sample code: No
  • Provided link: No