Skip to content

Commit

Permalink
Added docs for binding to ValueChanged (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissainty authored Oct 31, 2020
1 parent fe3c4a2 commit b7b3c68
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,42 @@ The `SelectedTemplate` is used to display the selected item and the `ResultTempl
}
```
Because you provide the search method to the component, making a remote call is really straight-forward. In this example, the `Debounce` parameter has been upped to 500ms and the `NotFoundTemplate` has been specified.

### Subscribing to changes in selected values
It is common to want to be able to know when a value bound to the Typeahead changes. To do this you can't use the standard `@bind-Value` or `@bind-Values` syntax, you must handle the change event manually. To do this you must specify the following parameters:

- Value
- ValueChanged
- ValueExpression
- TValue & TItem (these are not always necessary)

The code below shows an example of how these parameters should be used.

```razor
<BlazoredTypeahead SearchMethod="SearchPeople"
TValue="Result"
TItem="Result"
Value="selectedResult"
ValueChanged="SelectedResultChanged"
ValueExpression="@(() => selectedResult)"
placeholder="Search by name...">
</BlazoredTypeahead>
@code {
private MovieCredits movieCredits;
private Result selectedResult;
private async Task<IEnumerable<Result>> SearchPeople(string searchText)
{
var search = await client.SearchPerson(searchText);
return search.Results;
}
private async Task SelectedResultChanged(Result result)
{
selectedResult = result;
movieCredits = await client.GetPersonMovieCredits(result.Id);
}
}
```

0 comments on commit b7b3c68

Please sign in to comment.