Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

203
Views
Getting all selected values in Bootstrap5 Form.Control

I'm trying to get all selected values from a react-bootstrap Form. On the latest version of bootstrap e.target.value only seems to contain a single value instead of a list when multiple values are selected by shift clicking multiple lines. How can I get all selected values? Preferably by key or id.

const Form = ReactBootstrap.Form;
const Button = ReactBootstrap.Button;

const ExampleForm = () => {

  const [output, setOutput] = React.useState("");
  
  function changeSelection(e) {
    setOutput(e.target.value);
  }
  
  function handleSubmit(e) {
    e.preventDefault();
  }
  
  return(
    
    <Form onSubmit={handleSubmit}>
      <Form.Group controlId="dimension">
        <Form.Control 
          as="select" 
          multiple 
          onChange={changeSelection}>
          <option key="1" id="1" >1</option>
          <option key="2" id="2" >2</option>
          <option key="3" id="3" >3</option>
          <option key="4" id="4" >4</option>
        </Form.Control>
        <Button type="submit" variant="primary">
                select
        </Button>
      </Form.Group>
      Output: {output}
    </Form>

  );

}

ReactDOM.render(
    <ExampleForm />,
    document.getElementById('app')
);

Codepen example can be found here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Turns out you can use Array.from

Array.from(e.target.selectedOptions, option => option.value)

Found here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!