question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot specify default selected options for <select multiple />

See original GitHub issue

http://jsfiddle.net/qbAv6/

/** @jsx React.DOM */

var MultipleSelect = React.createClass({
  render: function() {
    return <select multiple>
      <option value='1' selected>A</option>
      <option value='2' selected>B</option>
      <option value='3' selected>C</option>
    </select>;
  }
});

React.renderComponent(<MultipleSelect />, document.body);

Expect option A, B and C are selected by default but they are not.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
sompylasarcommented, Jun 13, 2014

@zpao The docs on forms could be clearer by mentioning that you can put an array into the value attribute (the usage example is likely to be <select multiple>).

1reaction
sophiebitscommented, Dec 17, 2013

I think you forgot to save your jsfiddle, but as the console warning you get says,

Use the `defaultValue` or `value` props on <select> instead of setting `selected` on <option>. 

In this case, you want <select multiple value={['1', '2', '3']}> or with defaultValue if you want an uncontrolled component. For more info, see the docs on forms.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I set the default value for an HTML <select> element?
Provide "selected" keyword inside the option tag, which you want to appear by default in your drop down list. Or you can also...
Read more >
Cannot select multiple objects in AutoCAD
On the Cursor & Selection tab, clear the Use Shift key to add to selection option. User-added image; Choose OK to close the...
Read more >
Setting default values in a question with multiple dropdowns ...
Yes, Correct. If the first select has a value "Blank option/Select text" then the second select/dropdown has a no values. It will be...
Read more >
Not able to set multi-select default values on a form?
Post a question about using the core Smartsheet application: Sheets, Forms, Reports, Dashboards, and more.
Read more >
How to set the default value for an HTML <select> element
The select tag in HTML is used to create a dropdown list of options that can be selected. The option tag contains the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found