md-autocomplete setting search-text as selected-item
I have this
<md-autocomplete
md-selected-item="SelectedSupervisor"
md-search-text="SearchTerm"
md-delay="3000"
md-items="supervisor in MyFilter(SearchTerm)"
md-min-length="4"
placeholder="Search for Supervisor"
md-menu-class="autocomplete-custom-template">
$scope.SearchTerm is simply a string value that I use.
However, whenever I click on one of the records of the autocomplete, which would be something like this:
$scope.SelectedSupervisor = {
Id: 0,
Name: ""
}
(Obviously, depending on the selected-item, the value would change for this variable). That value for example is set to $scope.SearchTerm, which of course makes my app crash since most functions on my app use $scope.SearchTerm itself as a string.
Why does the click on record set the value of $scope.SearchTerm as that of the selected item?
The search text is a two-way binding. So, if the user types some text, it will obviously change, but if the component changes it, it makes sure to update the binding. The binding is used to fill the input element (since it is text-only) so users know which item was selected.
I guess I'm having a bit of trouble understanding what your exact issue is. Can you please provide a Codepen which demonstrates it so we can provide feedback?
For example searchtext is a variable in scope of string type..but when user selects something from dropdown suggestion which are not string but some other objects ..it will change searchtext to selected object..
perhaps u dont need to manually assign the search text to selected item. Right now on change event its assigning. On Mar 17, 2016 3:42 AM, "Topher Fangio" [email protected] wrote:
The search text is a two-way binding. So, if the user types some text, it will obviously change, but if the component changes it, it makes sure to update the binding. The binding is used to fill the input element (since it is text-only) so users know which item was selected.
I guess I'm having a bit of trouble understanding what your exact issue is. Can you please provide a Codepen which demonstrates it so we can provide feedback?
— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/7548#issuecomment-197509617
Ah, I think I understand now. Perhaps you want to use the md-item-text attribute to convert it to a string properly?
@topherfangio moved to you as you are responsible for this component
@usamakhalil86 Did you get this working using the md-item-text as outlined above?
Closing do to lack of timely response.
Is this issue fixed ? I am facing a similar one... Sometimes if searchText is set as object causes issues to functions which expects the searchText to be String all the time.
@maheshk172 Please open a new issue and provide a Codepen so that we can better understand your issue.