Topic: Need JS to hide modal

JP1968 pro asked 5 years ago


Expected behavior Need a better example than what is in the documentation.

*Actual behavior*Modal not hiding as expected.

Resources (screenshots, code snippets etc.)



There's no need to use js here - the problem is somewhere else, but the solution is really easy. Please put your .modal-dialog into:

<div class="modal fade" id="modalDiscount">
[...]
</div>

I also added the ID to your modal so you could use the button to launch the modal


TriSys free answered 5 years ago


Well, your examples do not make it simple, for example this one was generated for me from your site: https://mdbootstrap.com/snippets/jquery/trisys/1208885

The modal shows BEFORE the LAUNCH MODAL button is clicked.

Can we have a sample fully coded in Javascript which: 1. Show the modal 2. Does not close when the user clicks anywhere except the modal buttons 3. Captures a button click 4. Close the modal via Javascript in this button click.



As we mentioned in our modals documentation, you can hide the modal like this: $('#YourModal').modal('hide');

Could this be more simple?


snirkleshift free commented 3 years ago

This will not work in version 5. Is there another way of doing this now?


Marcin Luczak staff commented 3 years ago

Hi,

You can find the method for hiding MDB5 Modal in our documentation in the API -> Methods section. https://mdbootstrap.com/docs/standard/components/modal/#api-section-methods.

Best, Marcin



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

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.8.4
  • Device: MAC
  • Browser: All
  • OS: Mohavi
  • Provided sample code: No
  • Provided link: No