Closed igler closed 10 years ago
There's definitely a bug filtering using Angular's filter
-- both the option list and the model are not updating correctly.
I did a couple tests and other Angular array filters, limitTo
and orderBy
, filter correctly. I can't say I've used them extensively though with angular-selectize.
Also, I've set up an angular-selectize plunk -- http://plnkr.co/edit/4BuWxF. Just wanted to point that out in case it's of use testing.
The code I use is
<select multiple
ng-model="$parent.selectedLocationCountries"
ng-options="country.id as country.name for country in locationCountries | filterSelectableLocationCountries:$parent | orderBy:'name'"
selectize="$parent.selectizeConfig">
</select>
Hopefully this is correct and makes sense. At the moment (using latest 1.1.3 version) I get an "Uncaught TypeError: Cannot read property '0' of undefined" in line 107 of angular-selectize.js). When I debug the optionsProperty
it is locationCountries | filterSelectableLocationCountries:$parent | orderBy:'name'
and probably in scope.$parent
nothing is found. There is definitely a bug in here. You'll notice that the scope.$parent[optionsProperty] in getSelectedItems() fails to find the field in the scope.$parent when optionsProperty contains a | filter.
Also, there is another bug where changing the options doesn't check if the old model is in the new option set, so you may end up with a model for an option that doesn't exist.
I've only done some testing in single-selection mode. I'm sorry, I'm unable to spend time trying to fix it but wanted to indicate what I saw.
I looked a little closer, basically you can't use scope.$parent[optionsProperty] in getSelectedItems when the options has a filter on it.
Replace it with scope.$parent.$eval(optionsProperty) to properly evaluate it (or evaluate it once and use the variable in the rest of the function).
This actually fixes both of my problems so far.
Thank you @stgeorge -- appreciate all the helpful information you provided as well as what seems to be a viable solution to the filtered ngOptions
expression problem.
I know you earlier indicated you may not be able to submit a fix, but that was before your follow up comment. Would you like to take a crack at a pull request? If not, I should have some time by the end of the week.
@EvanOxfeld, I've created a pull request (my first one, so apologies if anything went wrong).
I'm not able to run the tests just yet, so perhaps a test should be added. I should say I haven't tested this in multiple mode, so a more thorough test should be done.
Is something like
ng-options="option.id as option.name for option in options | filter1 "
(please not the | sign) possible?