How do you use the required attribute in the Select component? #4874
Replies: 1 comment 2 replies
-
First, if you are getting type errors, please do not point to the src directory in your import. Next, const Input = props => <components.Input {...props} required={props.selectProps.required} />
const RequiredSelect = props => <Select required={true} components={{ Input }} {...props} /> BUT you will run into an issue of it always failing as the default behavior of the select is to clear the input when selecting an option or blurring the input. This can be remedied by overriding the default behavior of the input by overriding the default onInputChange method. An example on how to do this can be found here: https://codesandbox.io/s/react-select-editable-and-selectable-6nfdv?file=/src/App.js:286-1013 Also, note that the commented section in the onInputChange can be used to reset the inputValue to the last selected option label if that is your preference. For further discussion on input validation you can refer to this issue: #4327 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want
<Select />
to be mandatory, but I don't know how.If I specify props
required
, the following error will be output.Beta Was this translation helpful? Give feedback.
All reactions