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)

Most upvoted comments

@crscaballero It’s not happening any more. Set the defaultValue property on the FormControl element 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 the value property of the option element

This is still an issue. defaultValue does not show in the select box if <option> children are present. The first option is shown instead.

Using value instead of defaultValue worked for me.

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 value on the <option>s.

Using value instead of defaultValue worked for me.