-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No results found option #780
Comments
Makes sense and it's a very reasonable request. The hard part will be coming up with an elegant way of supporting this. |
👍 to this! |
Is there currently any workaround for this? |
+1 |
1 similar comment
+1 |
It would be great if we could pass a template hash to the typeahead options.
The header and the footer also make sense to be defined globally. |
+1, this would be very useful for a typeahead where the user can create a new "item" to be in the list. ie... if text typed is not in the list the user can click to take an action like "add as option" |
+1 for this feature - any known workaround for that? |
+1 |
would be helpful. thanks. |
+1 |
3 similar comments
+1 |
+1 |
+1 |
…ets. Lays foundation for twitter#780.
+1 |
1 similar comment
+1 |
Has anyone got a solution for this? |
+1 |
3 similar comments
+1 |
+1 |
+1 |
It's not quite the same, but I came across this looking for a way to trigger an external action when there are no results (in my case I'm showing a large element with instructions which wouldn't fit in the typeahead menu). Here is how I trigger a 'typeahead:empty' event, the same could possibly be used to render a custom empty message in the menu: input.on('typeahead:asyncreceive', function() {
if ($(this).data('tt-typeahead').menu._allDatasetsEmpty()) {
$(this).trigger('typeahead:empty')
}
}) |
I found a workaround for the multiple First, I wrapped the input in a div to easily get back to the parent: $(element).wrap('<div class="my-typeahead"></div>'); Second, you will need to add a special class to the templates: {
notFound: '<div class="tt-suggestion tt-none">There are no results for your search.</div>',
} Next, I added a listener on the ...
.on('typeahead:render', function(e, objs, async, name) {
var nones = $(element).closest('.my-typeahead').find('.tt-none');
var suggestions = $(element).closest('.my-typeahead').find('.tt-suggestion.tt-selectable');
// Hide all notFound messages
nones.hide();
// Only show the first message if there are zero results available
if(suggestions.length === 0) {
nones.first().show();
}
});
... What this does for me is that it only displays one of the |
Thanks @lucaspiller and @atrain0789 Here's another approach building on the snippet from @lucaspiller: const emptyMessage = `<div class="empty-message">
No matches found.
</div>`;
const emptyMessageNode = $(emptyMessage);
// hide empty message by default
emptyMessageNode.hide();
// get menu element and append hidden empty messsage element
const menuNode = $('.typeahead.tt-input').data('tt-typeahead').menu.$node;
menuNode.append(emptyMessageNode);
$('.typeahead').on('typeahead:asyncreceive', function () {
if ($(this).data('tt-typeahead').menu._allDatasetsEmpty()) {
// hide dataset result containers
menuNode.find('.tt-dataset').hide();
// show empty message and menu
emptyMessageNode.show();
menuNode.show();
} else {
// show dataset result containers
menuNode.find('.tt-dataset').show();
// hide empty message
emptyMessageNode.hide();
}
}); |
+1 |
I think I've found a simple solution for only showing one empty template, when working with multiple datasets. 1. Add an empty template to one dataset
2. Add event trigger keyup for the typeahead input field (.tt-input)
|
Works, but I also added it after async request results that I monitor on start and end by listening events |
I know that I can specify an
empty
template for each dataset, but I have 6 or 7 datasets and I would like to specify something to be displayed when none of the datasets have hits.If I just type in "4q8nywrfxm", I don't want to see 6 datasets all saying that they can't find that text, I just want one message, specified at the typeahead level (not the dataset level).
Does that make sense?
The text was updated successfully, but these errors were encountered: