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.

Creating new options with AsyncCreatable and Modal

See original GitHub issue

I am attempting to use the AsyncCreatable component and would like to open up a modal when a user attempts to create a new option (to gather more information for the option).

I tried passing in onNewOptionClick to the component, but I am not seeing a way to add the new option after the user has finished with the modal.

I’m thinking perhaps onNewOptionClick can be passed in a callback function that adds the option once the function is ready.

Something like:

if (isOptionUnique) {
  const callback = (option) => {
    options.unshift(option);

    this.select.selectValue(option);
  };

  if (onNewOptionClick) {
    onNewOptionClick(option, callback);
  } else {
    callback(option);	
  }
}

Is there already a better/existing way to accomplish this?

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
nafgcommented, Nov 27, 2017

There’s a workaround described here that worked for me: http://www.shahqaan.com/blog/react-select/ Basically, skip onNewOptionClick – use onChange and detect whether it’s a “regular” option or the new option placeholder by testing what properties it has. For instance the placeholder option is given a className property. In my case, my options have a data property so I test if it’s not there instead.

0reactions
bladeycommented, May 28, 2020

Hello -

In an effort to sustain the react-select project going forward, we’re closing old issues.

We understand this might be inconvenient but in the best interest of supporting the broader community we have to direct our limited efforts to maintain the latest version.

If you aren’t using the latest version of react-select please consider upgrading to see if it resolves any issues you’re having.

However, if you feel this issue is still relevant and you’d like us to review it - please leave a comment and we’ll do our best to get back to you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creatable - React Select
React Select. A flexible and beautiful Select Input control for ReactJS with multiselect, autocomplete, async and creatable support. Star.
Read more >
Create an asynchronous Bootstrap 4 modal with React
In a recent project, we wanted a simple way to open a modal in our app asynchronously with custom content. So the solution...
Read more >
How to load React-select Async with initial options for edit item ...
React-select will get the data by using a search API that I have and will insert the query behind by using this method:...
Read more >
Task asynchronous programming model - Microsoft Learn
Learn when and how to use Task-based async programming, a simplified approach to asynchronous programming in C#.
Read more >
Getting Started | Creating Asynchronous Methods - Spring
To model the user representation, create a resource representation class. To do so, provide a plain old Java object with fields, constructors, and...
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