Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Close Modal from JS/JQuery

triklimops-org priority asked 2 years ago


Expected behavior I have a Modal with a form on it. Because I want to validate the form and save information, I don't want the modal to close until I'm done with those actions. The modal closes when I use the inline data-mdb-dismiss="modal" in the HTML, but I can't figure out what to call in JavaScript to close the modal once my form is saved.

I tried doing the hide method like below, but it didn't work.

const myModalEl = document.getElementById('myModal')
const modal = new mdb.Modal(myModalEl)
modal.hide()

I then tried a hack approach of just hiding the modal and the background myself:

$("#compose-modal").hide();
$(".modal-backdrop").remove();

I thought this worked, but it seems to have some things still going on that make the page not work correctly.


Dawid Wajszczuk staff commented 2 years ago

Hi. Do you have any errors in console? You can try the solution from this snippet: https://mdbootstrap.com/snippets/standard/d-wajszczuk/3855179.



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Opened

Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 3.11.0
  • Device: Computer
  • Browser: Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No