AutoComplete for address lookup

5 posts, 0 answers
  1. Craig
    Craig avatar
    6 posts
    Member since:
    May 2016

    Posted 05 Oct 2017 Link to this post

    Hi there

    I can't get the AutoComplete control to update it's ItemsSource via data binding.  Everything appears to go smoothly...  I use the OnPropertyChanged event to update the ObservableCollection<string> in the model, and then call RaisePropertyChanged("SearchResults"), but nothing happens client side.  It's still attached to the original list of test items I started with.  I don't replace the ObservableCollection, I'm clearing it and then added the new values.  If I try to replace the collection, the application crashes.

    xaml

    <input:RadAutoComplete
        x:Name="AutoCompleteAddress"
        Watermark="Search here..."
        ItemsSource="{ Binding SearchResults }"
        PropertyChanged="AutoCompleteAddress_OnPropertyChanged"
        CompletionMode="Contains"/>

     

    Code Behind

    private void AutoCompleteAddress_OnPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "Text")
        {
            var addressDetailsPageModel = (AddressDetailsPageModel)BindingContext;
            addressDetailsPageModel.SearchAddress(AutoCompleteAddress.Text.Trim());
        }
    }

     

    Page Model

    public async void SearchAddress(string searchText)
    {
        var searchResults = await _addressSearchService.SearchAsync(searchText);

        SearchResults.Clear();

        foreach (var searchResult in searchResults)
            SearchResults.Add(searchResult);

        RaisePropertyChanged("SearchResults");
    }

    public ObservableCollection<string> SearchResults { get; set; }

     

    Any ideas?

     

    Cheers

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    665 posts

    Posted 09 Oct 2017 Link to this post

    Hello, Craig,

    We are currently working on resolving the crash that is observed when changing the ItemsSource of the AutoComplete at runtime. Here is the feedback item which I suggest you follow in order to receive automatic notifications - AutoComplete exception.

    In the meantime, raising a PropertyChanged event for the ObservableCollection is redundant as the collection provides a built-in functionality of raising property changed when adding/removing items. The behavior is a bug in the iOS/Android implementations of the control from our side. I have logged the behavior in our system - AutoComplete: ObservableCollection notification changes are not respected.You can follow it by subscribing to the item so that you can receive automatic notifications. I have added some points to your account for reporting the issue. In the meantime, we should come up with a fix for the exception thrown when changing the ItemsSource soon so you can use it as a workaround(we expect it to be available with the ServicePack release which is planned for the 18th of October).

    Regards,
    Stefan Nenchev
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Umair
    Umair avatar
    4 posts
    Member since:
    Apr 2016

    Posted 04 Nov 2017 in reply to Stefan Nenchev Link to this post

    Hi,

    any Updates on this?

    I want to assign values to the Autocomplete. please note, the values are retrieved from the server using async operation. 

  4. Umair
    Umair avatar
    4 posts
    Member since:
    Apr 2016

    Posted 06 Nov 2017 Link to this post

    Found a solution and it's working for me

    public static readonly BindableProperty ItemsProperty =
                  BindableProperty.Create("Items", typeof(IEnumerable<object>), typeof(MyAutocomplete), default(IEnumerable<object>),
                      defaultBindingMode: BindingMode.TwoWay,
                      propertyChanging: (bindable, oldValue, newValue) =>
                      {
                          MyAutocomplete_ = (MyAutocomplete)bindable;
                          _.ItemsSource = new List<object>(); // does the trick
                          _.ItemsSource = (IEnumerable)newValue;
                      });
  5. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    665 posts

    Posted 08 Nov 2017 Link to this post

    Hello, Umair,

    Thank you for sharing the approach with the community.

    In the meantime, I can confirm that the issue where changing the ItemsSource at runtime results in an exception is fixed with R3 2017 SP. We have not started working on the second one though.

    Regards,
    Stefan Nenchev
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top