-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New feature: allow displaying information when there is no record found #1011
Conversation
Thanks, I need this functionality as well. I was thinking of using a single read-only choice as a workaround. Lots of tickets related to this: #121 #831 #615 #152 I wonder if it would make sense to genericize this as a non-selectable static choice instead of adding a new top-level directive, as discussed in this issue: #152 Like maybe <ui-select-choices>
<li repeat="person in people | filter:$select.search">{{person.name}}</li>
<li ng-if="canAddNew">Add {{$select.search}}</li>
<li ui-select-no-choices>There are no choices!</li>
</ui-select-choices> |
Maybe it makes sense to separate the two. Separating the two makes the code clearer and easier to maintain. They are really 2 different cases which should be handled separately. Do you agree? |
Personally I could work with either. I don't know the ui-select codebase so I can't really comment on what's the better implementation design. But yes, semantically I think a "no results" message isn't really a search choice. Another way to look at this would be the ability to template the search choice dropdown itself, and by doing so add custom text to the dropdown below the choices. This could be used both for no results state and for if you wanted to add static help text even when there are results. This might be useful to me because I use |
Nice! We could really use this in our project -- for now we're using a workaround with a flagged "no results" item, very sub-optimal. |
Would be great if this PR would be merged, it seems like such a basic function missing from this otherwise great plugin.. on a more general note, is this plugin still maintained? PRs and issues seem to be piling up. @dimirc |
+1 |
1 similar comment
+1 |
@euzureau if there's only this flagged item, and user tabs out, the component select this instead of doing nothing, which is clearly a bug. How do you handle it? |
|
||
var transcludedNoChoice = transcluded.querySelectorAll('.ui-select-no-choice'); | ||
transcludedNoChoice.removeAttr('ui-select-no-choice'); //To avoid loop in case directive as attr | ||
transcludedNoChoice.removeAttr('ui-select-no-choice'); // Properly handle HTML5 data-attributes |
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.
Can I ask you why do you have this removeAttr(...)
two identical times?
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.
that was a mistake, pushed another commit.
@awerlang I belive they could manually remove this element after selection - user selects, |
@awerlang Thanks for pointing that out -- we had a nasty hack in there to block the click but I didn't think about the tab out. I just fixed that now by adding a little conditional in the on-select. If the no-results flag was selected, $select.selected = undefined. Thanks! :-) |
Not sure why, but resetting the model as suggested by @aszmyd didn't work, but @euzureau fix works most of the time. If user tabs out fast, while refresh not finished yet, the problem persists. But I guess this is good enough. I could use some fork like #1011 or #1075 but would like to stick with the official release. |
How can we use this? |
+1 |
5 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
@khanhto can you add documentation and squash these commits? |
+1 |
This is a nifty feature - I would recommend adding a test for this. |
@aaronroberson : How to squash the commit? Sorry, this is the first time I create a pull request. |
@khanhto Here is a good walkthrough: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html Congrats on making your first PR! |
15255eb
to
fcd1eb4
Compare
@aaronroberson I did not know that. I squashed the commits. Looks like we could also use "git reset" for that. Thanks |
The wiki needs updating too https://github.com/angular-ui/ui-select/wiki |
@user378230 and @wesleycho I went ahead and merged this in but will wait on a PR from the community for updates to the wiki and a PR for the unit tests before releasing. |
@aaronroberson I added some quick docs in the wiki for the new directive. |
All that's left is the tests, but I'm pretty short on time. Maybe in a few weeks haha. |
Where you planned to release this feature? I really need it in my project. |
Thanks @tannerlinsley! @styopdev just waiting for unit tests. |
While this feature is not in available you can use "ui-disable-choice" directive. <ui-select ng-model="someModel">
<ui-select-match><% $item.name %></ui-select-match>
<ui-select-choices repeat="item in items track by $index" ui-disable-choice="item.id === undefined">
<span ng-if="item.id"><% item.name %></span>
<span ng-if="item.id === undefined">No results...</span>
</ui-select-choices>
</ui-select> $http.get('/user/search', {
params: someSearchParams
}).then(function(response) {
if (response.data.length === 0) {
$scope.items = [{name: 'No results...'}];
} else {
$scope.items = response.data;
}
}); The purpose of the code above is to insert |
@MEGApixel23 Thanks for reply, I knew about this solution, but I had to change parent |
@styopdev Could you provide an example, please? It looks like an interesting solution. |
@MEGApixel23 I have copied template that I need from source code to my .js file
|
nice job on this. did anyone make progress on a selectize compatible version? |
I'm using ui-select in my project as it's a cool component. In my project, I really need the ability to show information when there is no record found. Looks like it's not implemented yet so I'm pushing this pull request for discussion.
I would like to create a separate directive (uiSelectNoChoice) to specify a template to be displayed when there is no record.
We can use it like this:
At the moment, I only implement it for bootstrap theme (for discussion purpose). If you guys think this is desirable and agree with the approach, we will go ahead with select2 and selectize theme.
Regards,
Khanh