Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting initial/default label for Select.Async #1138

Closed
yonaichin opened this issue Aug 3, 2016 · 8 comments
Closed

Setting initial/default label for Select.Async #1138

yonaichin opened this issue Aug 3, 2016 · 8 comments

Comments

@yonaichin
Copy link

As title states, setting initial value for Select.Async is possible but failed to show the label due to the empty callback options from loadOptions.

Is there any workaround ?
I tried #861 but not quite fit the scenario.
Thanks in advance.

@tingwei628
Copy link

tingwei628 commented Aug 31, 2016

Here is my workaround...
I marked on Select and depended on the state "isFirstTime"

constructor() {
   this.state = {
      isFirstTime: true,
  };
 this.loadAsyncOptions= this.loadAsyncOptions.bind(this);
}
loadAsyncOptions(input, callback) {
   if(input) {
      if (this.state.isFirstime) {
       this.setState({
           isFirstTime: false,
        });
        callback(null, options: [ { ... } ]); // your default options
        return;
      }
      callback(null, options: [ {  ...  } ]); // other options...
      return;
   } 
}
render() {
return(<div>
  <Select.Async
    loadOptions={this.loadAsyncOptions} 
   /></div>);
 }

@yonaichin
Copy link
Author

yonaichin commented Sep 1, 2016

Thanks for the reply.
I actually have this problem fixed with my workaround and send a PR.
So far, it works just fine.
For your reference, #1180

@dstuecken
Copy link

I actually created another PR that will fix this issue as well: The ability to pass an options array to Select.Async.

@bvaughn
Copy link
Collaborator

bvaughn commented Sep 18, 2016

FYI I am working on a refactor for Async that should address this issue. (See PR #1226)

@bvaughn
Copy link
Collaborator

bvaughn commented Sep 18, 2016

Resolved via PR #1226.

Look for an RC2 to come out (hopefully) sometime today with this change.

@bvaughn bvaughn closed this as completed Sep 18, 2016
@zhaoyi0113
Copy link

How does the initial value work? Is there an example for that? I tried defaultOptions, defaultValues but none of them work.

@zhaoyi0113
Copy link

I see why it doesn't work for me. The defaultValues in my component is also an async request. How can I make it work with async data?

@ngohieutp
Copy link

I see why it doesn't work for me. The defaultValues in my component is also an async request. How can I make it work with async data?

As 2020, is there any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants