when adding isValidNewOption the 'create ""' option is always on
See original GitHub issueAre you reporting a bug or runtime error?
i want to add validation on new options but it seems to change the default behavior when I’m clicking on the input
import React, { Component } from 'react';
import CreatableSelect from 'react-select/creatable';
const options = [
{ value: 'chocolate', label: 'Chocolate' },
{ value: 'strawberry', label: 'Strawberry' },
{ value: 'vanilla', label: 'Vanilla' }
]
export default class CreatableSingle extends Component<*, State> {
handleChange = (newValue: any, actionMeta: any) => {
console.group('Value Changed');
console.log(newValue);
console.log(`action: ${actionMeta.action}`);
console.groupEnd();
};
handleInputChange = (inputValue: any, actionMeta: any) => {
console.group('Input Changed');
console.log(inputValue);
console.log(`action: ${actionMeta.action}`);
console.groupEnd();
};
render() {
return (
<CreatableSelect
isClearable
onChange={this.handleChange}
onInputChange={this.handleInputChange}
options={options}
isValidNewOption={() => true}
/>
);
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:9
Top Results From Across the Web
Creatable grouped options show "create" option ...
When there is no grouping, no option is shown to create "Ocean" if it already exists, which is the behaviour I would expect....
Read more >Adding labels to react-select breaks functionally
I managed to dive into the issue. The solution was to write your own isValidNewOption to replace the builtin and pass it as...
Read more >API - React Select
isValidNewOption. Determines whether the "create new ..." option should be displayed based on the current input value, select value and options array.
Read more >Getting started with react-select - YouTube
In this video, we will learn how to create select components for React.0:00 Introduction1:10 Installing React Select2:22 Jumping into ...
Read more >API
Sets the position of the createOption element in your options list. ... isValidNewOption function = (inputValue, selectValue, selectOptions) => undefined.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@praveen7557 is this what you are looking for?
https://codesandbox.io/s/brave-moon-7y0vb?file=/src/App.js
@praveen7557 version 4 introduced new lifecycle methods to make it work with React v17, so you would need to change the version of React to v16 to make it work in the codesandbox. Here is the same example working against version react-select v3.1
https://codesandbox.io/s/brave-moon-7y0vb?file=/src/App.js