I have been asked to make the filter input (search box) appear at the top of the dropdown list in a multiselect exactly like it does in the dropdownlist component. Is there a way to move the filter input out of the box at the top and into the search area? The expected behavior is this:
- User clicks on the dropdownlist (or the down arrow)
- The list opens displaying a search (filter) input at the top just like the dropdownlist does.
- User types in the filter and the list filters the results.
- User clicks on one of the items and it adds a chip above.
1 Answer, 1 is accepted
Hello, Lee,
You can use the header template to render an input in the header of the multiselect component. The logic itself is a bit tricky as the MultiSelect is not designed to have a searchbox inside its popup by default.
I've created a Dojo for you to examine, however keep in mind that this solution does not take WAI-ARIA into consideration so there could be accessibility problems.
Dojo
https://dojo.telerik.com/@gdenchev/ahocAlep
Best Regards,
Georgi Denchev
Progress Telerik
Hi, Lee,
The list(dropdown/popup portion) excludes certain elements from obtaining focus/being interactable. That is also why the custom logic with the `element.focus` is required in order for the user to be able to type in the input inside the popup.
You could try to add the 'focus' logic to a `click` handler on the input.
$(document.body).on("click", "[role='searchbox']", (e) => {
let search = $("[role='searchbox']");
ms.one("close", (ev) => {
ev.preventDefault();
});
kendo.focusElement(search);
});
As for the regular input, if you don't want the user to be able to type in it, you can set it to readonly.
let ms = $("#multiselect").data("kendoMultiSelect");
ms.input.attr("readonly", "true");
Dojo
https://dojo.telerik.com/@gdenchev/ediyiPaZ
Best Regards,
Georgi
Hi, Lee,
The filter input is not something that is available in the multiselect as the widget's input itself is meant to serve that purpose. That is why there will likely be corner cases with the custom implementation.
I've made some slight modifications, however there's no guarantee everything will work out of the box. You can either extend the logic or my personal recommendation would be to simply stick to the built-in functionality.
// Changes are highlighted in yellow
ms._typingTimeout = setTimeout(function() {
var value = $(e.target).val();
if (ms._prev !== value) {
ms._prev = value;
ms.search(value);
ms._toggleCloseVisibility();
} else if (value === "") {
ms.search(value);
ms._toggleCloseVisibility();
}
// Changes are highlighted in yellow
$("#multiselect").kendoMultiSelect({
dataSource: [
{ id: 1, name: "Apples" },
{ id: 2, name: "Oranges" }
],
filtering: function(e) {
if(event && $(event.target).is(e.sender.input)) {
e.preventDefault();
}
},
Dojo
Hi, Lee,
The MultiSelect is designed to work this way and there is no way to to change it to that extent, or at least no built-in settings to do so.
On the other hand, I would recommend that you open a FR in our feedback portal with your idea. This sounds either like a brand new widget or some other "mode" of the MultiSelect, however this is not up to me to decide. If the request garners enough interest, the managers will review it.
Best Regards,
Georgi
https://feedback.telerik.com/kendo-jquery-ui/1649561-make-search-in-multiselect-look-like-search-in-dropdown-list
Hi, Lee,
Thank you for submitting the FR!
I've approved it and moved it to unplanned.
Best Regards,
Georgi