Reset MDBSelectInput


Topic: Reset MDBSelectInput

Justin Martin asked 5 years ago

Hello,

I try to find a way to reset MDBSelectInput value. I tried to change the selected prop but it can not affect the input, because as doc explained : the selected prop is default value. So useless if a value is previously selected by user.

If you have any idea how to do it ?


A way to do is to have a select HTML element in a form and when you want to reset the select, use the native function reset() of the form (as exemple with a ref). (I tried with MDBSelect instead of select HTML, but it doesn't work with this one...)

Exemple works :

<form ref={this.formRef}>
    <select className="browser-default custom-select">
        <option value="">Select element</option>
         ...
     </select>
</form>

Jakub Chmura staff premium commented 5 years ago

Nice to hear that you found a solution!

Best, Kuba


ps : in your support's form the "version" field is bugged : sometimes we can't set value (and can't valid the form...)


Jakub Chmura staff premium answered 5 years ago

Hi @Justin Martin

If you want to control a select input you need to use Controlled select. MDBSelectInput is a part of an uncontrolled select component.

You can read more about this component in an API tab on the select documentation page:

I will report a problem with the "version" field to our team.

Best, Kuba


FREE CONSULTATION

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

Status

Closed

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: 4.27.0
  • Device: PC
  • Browser: Brave
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No