Topic: Reset form inside modal
Bernardo Santos free asked 3 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?
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
Krzysztof Wilk staff commented 3 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 3 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 3 years ago
You can use React hooks to detect that. Use controlled input and pass state as
value
property (remember to also provide anonChange
event) to your input component and use theuseEffect
hook to control it manually. You have to also passsetState
andisOpen
properties to your modal, so again - you can use theuseEffect
hook to detect changes. If this state is equal tofalse
- your modal is hidden and so on :)Keep coding!