From b7b3c6804804fa0d29d9310434ea76d7a0f66d19 Mon Sep 17 00:00:00 2001 From: Chris Sainty Date: Sat, 31 Oct 2020 23:28:02 +0000 Subject: [PATCH] Added docs for binding to ValueChanged (#182) --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index 1614ab2..5dfb8fc 100644 --- a/README.md +++ b/README.md @@ -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 + + + +@code { + private MovieCredits movieCredits; + private Result selectedResult; + + private async Task> 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); + } +} +``` +