1

Our website is styled with Bootstrap. I'm trying to implement a React-Bootstrap select component. How do I make it into a controlled component? More specificly, how do I mark the selected option. Usually it is with a value property in the parent component. Is this how it works for React-Bootstrap select as well? What function runs when a new option is selected? What are the parameters of the function?

1 Answer 1

1

After trial and error here is an example:

const applySelect = (event) => {someFunction(event.target.value)};
const selectedValue = 3;
return (
    <FormGroup controlId="formControlsSelect">
        <ControlLabel >Label String</ControlLabel>
        <FormControl componentClass="select" placeholder="select" value={selectedValue} onChange={applySelect}>
            <option value="0" key="0">Option 0</option>
            <option value="1" key="1">Option 1</option>
            <option value="2" key="2">Option 2</option>
        </FormControl>
     </FormGroup>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.