Clear Modal Form On Close


Topic: Clear Modal Form On Close

andy@ipower.uk.com asked a year 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 a year 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,


andy@ipower.uk.com commented a year ago

Great, Thank you so much


Mateusz Łubianka staff commented a year ago

I'm glad everything works

Best,


Please insert min. 20 characters.
Status

Resolved

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: jQuery
  • MDB Version: 4.13.0
  • Device: Windows 10
  • Browser: All
  • OS: WIndows 10
  • Provided sample code: No
  • Provided link: No
Tags