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

get onSuggestionSelected item #458

Open
TeodorKolev opened this issue Oct 20, 2017 · 3 comments
Open

get onSuggestionSelected item #458

TeodorKolev opened this issue Oct 20, 2017 · 3 comments

Comments

@TeodorKolev
Copy link

TeodorKolev commented Oct 20, 2017

How can I het onSuggestionSelected current suggestion (json object at that position)? thank you

@moroshko
Copy link
Owner

As docs suggest, the selected suggestion is available as suggestion.

function onSuggestionSelected(event, { suggestion })

@TeodorKolev
Copy link
Author

How to call that i here?

<Autosuggest
            suggestions={suggestions}
            onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
            onSuggestionsClearRequested={this.onSuggestionsClearRequested}
            getSuggestionValue={this.getSuggestionValue}
            renderSuggestion={this.renderSuggestion}
            inputProps={inputProps}
            onSuggestionSelected={() => {
              console.log('current suggestion')
            }}
          />

@mateodaza
Copy link

You can do it like this.

In your react component class, set the function like this.

 onSuggestionSelected = (event, { suggestion, suggestionValue, suggestionIndex, sectionIndex, method }) =>{
        //Here you do whatever you want with the values
        alert(suggestionValue); //For example alert the selected value
    };

Then when you render your it, call the function.

<Autosuggest
            suggestions={suggestions}
            onSuggestionsFetchRequested={this.onSuggestionsFetchRequested}
            onSuggestionsClearRequested={this.onSuggestionsClearRequested}
            getSuggestionValue={this.getSuggestionValue}
            renderSuggestion={this.renderSuggestion}
            onSuggestionSelected={this.onSuggestionSelected}.  //. <-----
            inputProps={inputProps}
            onSuggestionSelected={() => {
              console.log('current suggestion')
            }}
          />

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

3 participants