Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Expose $select.search for external / remote filtering. #31

Closed
wants to merge 7 commits into from

Conversation

mfzl
Copy link

@mfzl mfzl commented Feb 28, 2014

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.

@larsfjerm
Copy link

Pretty neat function, thanks! Exactly what I was looking for.

@MarcosRava
Copy link

Working 100% please accept the pull request!

@mfzl
Copy link
Author

mfzl commented Mar 20, 2014

@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.

@mfzl mfzl closed this Mar 20, 2014
@mfzl mfzl reopened this Mar 20, 2014
@tkrotoff
Copy link
Contributor

Thanks for the pull request and the example.
However I've implemented it in a different way, you can now provide a promise to the "repeat" expression.
Please check the demo.

@tkrotoff tkrotoff closed this Mar 25, 2014
tkrotoff added a commit that referenced this pull request Apr 1, 2014
See Expose $select.search for external / remote filtering #31
@tkrotoff
Copy link
Contributor

tkrotoff commented Apr 1, 2014

@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.
However there are some differences: refresh attribute is on choices instead of ui-select (makes more sense) + I've added debounce.

See commits 97624a1, f46e92c, 1e580d5

So thanks a lot :)

@mfzl
Copy link
Author

mfzl commented Apr 1, 2014

That looks much better. Thanks and welcome :)


ctrl.refresh = function() {
$timeout(function() {
$scope.$apply($attrs.refresh);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not necessary to $scope.$apply() inside a $timeout()

@tkrotoff or @faxal perhaps you can remove it?

Copy link
Contributor

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use $scope.$eval() then.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See a873eb0

@mike-marcacci
Copy link

Has this functionality been removed or its interface intentionally changed? The syntax described above has no effect.

@mike-marcacci
Copy link

Ah, I answered my own question. In case anyone else finds their way here:

This is to be bound to the ui-select-choices child directive and not the ui-select one. See the following, which binds yourRefreshHandler:

<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 refresh-delay="300" which controls debounce.

@developer10
Copy link

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

@deitch
Copy link

deitch commented Oct 5, 2014

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.

@dimirc
Copy link
Contributor

dimirc commented Oct 8, 2014

@deitch I'd really appreciate if you can help pushing a PR with this to docs

@deitch
Copy link

deitch commented Oct 9, 2014

Sure, I will be happy to.

@deitch
Copy link

deitch commented Oct 9, 2014

@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...)?

@dimirc
Copy link
Contributor

dimirc commented Oct 9, 2014

Actually I opened #112 long ago that we could use to start improving documentation. Will be better to create this demo on the gh-page branch. Any help let me know and thanks for helping.

@deitch
Copy link

deitch commented Oct 10, 2014

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.

@deitch
Copy link

deitch commented Oct 10, 2014

Oh, ghpages is such a pain...

@alflennik
Copy link

Great feature, just what I needed, but it looks like it's not in the docs?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.