-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expose $select.search for external / remote filtering. #31
Conversation
Pretty neat function, thanks! Exactly what I was looking for. |
Working 100% please accept the pull request! |
@devesh For my use case I wanted to have all the control inside caller. I had the same issue, I used $q.defer() to remedy it a little for the demo. |
Thanks for the pull request and the example. |
See Expose $select.search for external / remote filtering #31
@faxal your approach is more flexible for the user than letting him specify a promise inside the repeat expression. So after some experiments, I've reverted my changes and opted for your approach. See commits 97624a1, f46e92c, 1e580d5 So thanks a lot :) |
That looks much better. Thanks and welcome :) |
|
||
ctrl.refresh = function() { | ||
$timeout(function() { | ||
$scope.$apply($attrs.refresh); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ProLoser $attrs.refresh is a string (ex: "refreshAddresses($select.search)") with function refreshAddresses() being declared by the user on the scope (see demo.js#L72).
$scope.$apply() performs an $eval(expr) that's why it works.
$timeout does perform $apply() but without passing any parameter: timeout.js#L52.
$attrs.refresh is like a function pointer as a string. Sounds hackish like this, but it works well.
It is particulary smart, I would not have had the idea myself :)
btw here the current code: select.js#L185.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use $scope.$eval()
then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See a873eb0
Has this functionality been removed or its interface intentionally changed? The syntax described above has no effect. |
Ah, I answered my own question. In case anyone else finds their way here: This is to be bound to the <ui-select refresh="search($select.search)" ng-model="person.selected" theme="bootstrap">
<ui-select-match placeholder="Select or search a person in the list...">{{$select.selected.name}}</ui-select-match>
<ui-select-choices refresh="yourRefreshHandler($select.search)" refresh-delay="300" repeat="item in people | filter: $select.search">
<div ng-bind-html="item.name | highlight: $select.search"></div>
<small ng-bind-html="item.email | highlight: $select.search"></small>
</ui-select-choices>
</ui-select> Also note the presence of |
Is this fix included in the latest version? If so, how do I use it because I want to query the API based on current value of $search.select |
Can this be written up in the docs? the ui-select interface and code is so much better than the old ui-select2 - and easier to use - but remote querying is a central use case, and hard to figure out how to use. |
@deitch I'd really appreciate if you can help pushing a PR with this to docs |
Sure, I will be happy to. |
@dimirc do you just want an updated README.md? Or is there a separate docs dir or repo (that I cannot find, but that is probably just me...)? |
OK, I see it. There is not much there. I will add an example in there. You should have the link from angular-ui.github.io (the project ghpages branch), even if it is incomplete, it is a starting point. Right now there is only a link to the code. |
Oh, ghpages is such a pain... |
Great feature, just what I needed, but it looks like it's not in the docs? |
Here is a working plunkr, http://plnkr.co/edit/1keJMP?p=preview
My attempt at fixing #30. I'm not sure it's the best solution, but it's a start and I'm using it. Might help others.