react-bootstrap: FormControl componentClass="select" defaultValue doesn't work
How can I set the default value for a FormControl component that has its componentClass set to 'select'? For text FormControls it works fine, but for select it wont work.
I tried setting defaultValue and value properties in FormControl component, but it just doesn’t work, and also tried setting selected property in the corresponding option tag, but I got a warning that said I should use defaultValue or value properties instead, and eitherways the default value was not set.
Any suggestion?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 8
- Comments: 15 (3 by maintainers)
@crscaballero It’s not happening any more. Set the
defaultValueproperty on theFormControlelement and make sure the property actually gets there. I had this issue and turns out the property was not getting down to the actual component. In addition, make also sure that the default value is compatible with the value in thevalueproperty of theoptionelementThis is still an issue. defaultValue does not show in the select box if <option> children are present. The first option is shown instead.
thank you! you really saved me. this is crazy, the defaultValue doesn’t work but value works.
Works fine for me. Note that you need to set
valueon the<option>s.Using
valueinstead ofdefaultValueworked for me.Works here?
https://codesandbox.io/s/smoosh-dawn-38tfg?file=/src/App.tsx