Topic: Clear Modal Form On Close

Alindsay81 priority asked 4 years ago


Hello, I have a modal form based on the examples, when a user partially completes the form but presses cancel to close the modal the modal is not cleared, the next time the modal is opened the old content remains - i have tried various methods to clear the modal etc but i cant get any to work - i wonder if someone could suggest a method perhaps using js


Mateusz Łubianka staff answered 4 years ago


Hi @andy@ipower.uk.com,

Try to use hide.bs.modal function. This event is fired immediately when the hide instance method has been called. More info about it: https://mdbootstrap.com/docs/jquery/modals/basic/#options

$('#myModal').on('hidden.bs.modal', function (e) {

    $('#yourForm').find("input[type=text], textarea").val("");
})

Best,


Alindsay81 priority commented 4 years ago

Great, Thank you so much


Mateusz Łubianka staff commented 4 years ago

I'm glad everything works

Best,



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Resolved

Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB jQuery
  • MDB Version: 4.13.0
  • Device: Windows 10
  • Browser: All
  • OS: WIndows 10
  • Provided sample code: No
  • Provided link: No