Topic: Reset form inside modal

Bernardo Santos free asked 2 years ago


How do I reset a form inside a modal when a model is hidden.

I've tried to add a listener for hidden.mdb.modal event and reset the form but the mdb5 inputs label animation do not reset with form.reset() and the hidden.mdb.modal doesn't even occur.

What is the solution?


Krzysztof Wilk staff commented 2 years ago

Hi!

Do you use an MDB5 Standard package or MDB5 React one? The MDB5 React package is differrent than first one and these events won’t work ;( could you also provide a code for your problem? It will be very helpful :)

Keep coding!


Bernardo Santos free commented 2 years ago

I'm using the MDB React, if the events do not work with this one, how can I detect the modal closing when someone clicks outside of it or using escape key?


Krzysztof Wilk staff commented 2 years ago

You can use React hooks to detect that. Use controlled input and pass state as value property (remember to also provide an onChange event) to your input component and use the useEffect hook to control it manually. You have to also pass setState and isOpen properties to your modal, so again - you can use the useEffect hook to detect changes. If this state is equal to false - your modal is hidden and so on :)

Keep coding!



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: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: MDB5 1.4.0
  • Device: Web
  • Browser: Brave
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No
Tags