You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The short info segment that is currently provided is insufficient to use an `<select multiple={true}>` element.
This is especially confusing and frustraring with the sentence **"this makes it so that `<input type="text">`, `<textarea>`, and `<select>` all work very similarly"** right before it: In the case of using the `multiple` attribute, you *do* need to change your code a little bit more.
The linked anonymous codepen is from me, feel free to copy/paste/modify it as you like; afaik all codepen example are owned by @gaearon?
There is an [alternative codepen example](https://codepen.io/anon/pen/VOEezB?editors=0011) which also deals with writing a more suitable alert message, depending on how many options are selected, but in my opinion it adds unnecessary noice.
This issue has also been addressed in #531, #984.
Copy file name to clipboardExpand all lines: content/docs/forms.md
+52-7Lines changed: 52 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -182,13 +182,58 @@ class FlavorForm extends React.Component {
182
182
183
183
Overall, this makes it so that `<input type="text">`, `<textarea>`, and `<select>` all work very similarly - they all accept a `value` attribute that you can use to implement a controlled component.
184
184
185
-
> Note
186
-
>
187
-
> You can pass an array into the `value` attribute, allowing you to select multiple options in a `select` tag:
[**Try it on CodePen**](https://codepen.io/anon/pen/pmxJRd?editors=0011)
235
+
236
+
Notice that [Array.from()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from) is used to transform `event.target` into an array, so we can use the [filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) and [map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map) functions to obtain the values from the selected options.
0 commit comments