Display jquery ui autocomplete with categories horizontally and not verticallyIs there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How can I know which radio button is selected via jQuery?How to check whether a checkbox is checked in jQuery?Disable/enable an input with jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?
How can I use my cell phone's light as a reading light?
Was the 45.9°C temperature in France in June 2019 the highest ever recorded in France?
How do ballistic trajectories work in a ring world?
What was the nature of the known bugs in the Space Shuttle software?
What was the significance of Spider-Man: Far From Home being an MCU Phase 3 film instead of a Phase 4 film?
What exactly is a "murder hobo"?
Why do Martians have to wear space helmets?
Is this car delivery via Ebay Motors on Craigslist a scam?
How was the website able to tell my credit card was wrong before it processed it?
I'm feeling like my character doesn't fit the campaign
Function that detects repetitions
Wouldn't putting an electronic key inside a small Faraday cage render it completely useless?
Attach a visible light telescope to the outside of the ISS
Sense of humor in your sci-fi stories
My professor has told me he will be the corresponding author. Will it hurt my future career?
Why did the frequency of the word "черт" (devil) in books increase by a few times since the October Revolution?
Can we share mixing jug/beaker for developer, fixer and stop bath?
Can a USB hub be used to access a drive from two devices?
How would a sea turtle end up on its back?
Shipped package arrived - didn't order, possible scam?
What was the coded message that Happy Hogan sent to Nick Fury?
Why do most airliners have underwing engines, while business jets have rear-mounted engines?
What are some bad ways to subvert tropes?
How did the IEC decide to create kibibytes?
Display jquery ui autocomplete with categories horizontally and not vertically
Is there an “exists” function for jQuery?Add table row in jQueryHow do I check if an element is hidden in jQuery?Setting “checked” for a checkbox with jQuery?How can I know which radio button is selected via jQuery?How to check whether a checkbox is checked in jQuery?Disable/enable an input with jQuery?How can I refresh a page with jQuery?jQuery scroll to element“Thinking in AngularJS” if I have a jQuery background?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to display the autocomplete results horizontally instead of the default(vertical). I was able to do it but the issue is I cant select the item from the drop down anymore. I think because I used div instead of ul. And if I use ul jquery appends some un-wanted classes inline. Which messes up the horizontal behaviour
HTML
<label for="search">Search: </label>
<input id="search">
CSS
#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
JS
$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'></div>");
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+"");
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label );
);
);
https://codepen.io/nitinmendiratta/pen/aMMeOz
jquery jquery-ui-autocomplete
add a comment |
I am trying to display the autocomplete results horizontally instead of the default(vertical). I was able to do it but the issue is I cant select the item from the drop down anymore. I think because I used div instead of ul. And if I use ul jquery appends some un-wanted classes inline. Which messes up the horizontal behaviour
HTML
<label for="search">Search: </label>
<input id="search">
CSS
#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
JS
$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'></div>");
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+"");
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label );
);
);
https://codepen.io/nitinmendiratta/pen/aMMeOz
jquery jquery-ui-autocomplete
add a comment |
I am trying to display the autocomplete results horizontally instead of the default(vertical). I was able to do it but the issue is I cant select the item from the drop down anymore. I think because I used div instead of ul. And if I use ul jquery appends some un-wanted classes inline. Which messes up the horizontal behaviour
HTML
<label for="search">Search: </label>
<input id="search">
CSS
#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
JS
$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'></div>");
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+"");
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label );
);
);
https://codepen.io/nitinmendiratta/pen/aMMeOz
jquery jquery-ui-autocomplete
I am trying to display the autocomplete results horizontally instead of the default(vertical). I was able to do it but the issue is I cant select the item from the drop down anymore. I think because I used div instead of ul. And if I use ul jquery appends some un-wanted classes inline. Which messes up the horizontal behaviour
HTML
<label for="search">Search: </label>
<input id="search">
CSS
#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
JS
$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'></div>");
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+"");
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label );
);
);
https://codepen.io/nitinmendiratta/pen/aMMeOz
jquery jquery-ui-autocomplete
jquery jquery-ui-autocomplete
asked Mar 25 at 21:17
Nitin MendirattaNitin Mendiratta
234 bronze badges
234 bronze badges
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
That is widget tweeking I like!
The main mistake was not having a ul as direct parent of your custom li.
Then, Those custom li need the ui-menu-item class in order to be selected...
Lastly, you have to "override" the styling of the nested ul using !important. So they will be displayed as block with a relative position. Incidentally, without border...
And I removed an icon strangely showing...
It works fine in CodePen. It needed an additional CSS rule to work in the below snippet. (Don't ask me why!)
$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'><ul></ul></div>"); // Added <ul></ul>
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+" ul"); // added +" ul"
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label ).addClass("ui-menu-item"); // Added the addClass()
);
);
// Actual Code
$(function()
var data = [
label: "annhhx10", category: "Products" ,
label: "annk K12", category: "Products" ,
label: "annttop C13", category: "Products" ,
label: "anders andersson", category: "People" ,
label: "andreas andersson", category: "People" ,
label: "andreas johnson", category: "People"
];
$( "#search" ).catcomplete(
delay: 0,
source: data,
select: function(item, ui) // Added item, ui --- Arguments were missing.
console.log(ui.item.value);
$( "#search" ).val( ui.item.value );
return false;
);
);#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
/* ADDED STYLE */
.ui-autocomplete>li>div>ul
display: block !important;
position: relative !important;
border: 0 !important;
span.ui-menu-icon
display:none !important;
/* ADDED for the SO snippet only !! Not needed on CodePen */
.ui-autocomplete>li
display: inline-block !important;
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<label for="search">Search: </label>
<input id="search">
Thanks a lot it is working as expected. Appreciate it :)
– Nitin Mendiratta
Mar 26 at 13:30
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346534%2fdisplay-jquery-ui-autocomplete-with-categories-horizontally-and-not-vertically%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
That is widget tweeking I like!
The main mistake was not having a ul as direct parent of your custom li.
Then, Those custom li need the ui-menu-item class in order to be selected...
Lastly, you have to "override" the styling of the nested ul using !important. So they will be displayed as block with a relative position. Incidentally, without border...
And I removed an icon strangely showing...
It works fine in CodePen. It needed an additional CSS rule to work in the below snippet. (Don't ask me why!)
$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'><ul></ul></div>"); // Added <ul></ul>
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+" ul"); // added +" ul"
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label ).addClass("ui-menu-item"); // Added the addClass()
);
);
// Actual Code
$(function()
var data = [
label: "annhhx10", category: "Products" ,
label: "annk K12", category: "Products" ,
label: "annttop C13", category: "Products" ,
label: "anders andersson", category: "People" ,
label: "andreas andersson", category: "People" ,
label: "andreas johnson", category: "People"
];
$( "#search" ).catcomplete(
delay: 0,
source: data,
select: function(item, ui) // Added item, ui --- Arguments were missing.
console.log(ui.item.value);
$( "#search" ).val( ui.item.value );
return false;
);
);#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
/* ADDED STYLE */
.ui-autocomplete>li>div>ul
display: block !important;
position: relative !important;
border: 0 !important;
span.ui-menu-icon
display:none !important;
/* ADDED for the SO snippet only !! Not needed on CodePen */
.ui-autocomplete>li
display: inline-block !important;
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<label for="search">Search: </label>
<input id="search">
Thanks a lot it is working as expected. Appreciate it :)
– Nitin Mendiratta
Mar 26 at 13:30
add a comment |
That is widget tweeking I like!
The main mistake was not having a ul as direct parent of your custom li.
Then, Those custom li need the ui-menu-item class in order to be selected...
Lastly, you have to "override" the styling of the nested ul using !important. So they will be displayed as block with a relative position. Incidentally, without border...
And I removed an icon strangely showing...
It works fine in CodePen. It needed an additional CSS rule to work in the below snippet. (Don't ask me why!)
$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'><ul></ul></div>"); // Added <ul></ul>
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+" ul"); // added +" ul"
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label ).addClass("ui-menu-item"); // Added the addClass()
);
);
// Actual Code
$(function()
var data = [
label: "annhhx10", category: "Products" ,
label: "annk K12", category: "Products" ,
label: "annttop C13", category: "Products" ,
label: "anders andersson", category: "People" ,
label: "andreas andersson", category: "People" ,
label: "andreas johnson", category: "People"
];
$( "#search" ).catcomplete(
delay: 0,
source: data,
select: function(item, ui) // Added item, ui --- Arguments were missing.
console.log(ui.item.value);
$( "#search" ).val( ui.item.value );
return false;
);
);#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
/* ADDED STYLE */
.ui-autocomplete>li>div>ul
display: block !important;
position: relative !important;
border: 0 !important;
span.ui-menu-icon
display:none !important;
/* ADDED for the SO snippet only !! Not needed on CodePen */
.ui-autocomplete>li
display: inline-block !important;
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<label for="search">Search: </label>
<input id="search">
Thanks a lot it is working as expected. Appreciate it :)
– Nitin Mendiratta
Mar 26 at 13:30
add a comment |
That is widget tweeking I like!
The main mistake was not having a ul as direct parent of your custom li.
Then, Those custom li need the ui-menu-item class in order to be selected...
Lastly, you have to "override" the styling of the nested ul using !important. So they will be displayed as block with a relative position. Incidentally, without border...
And I removed an icon strangely showing...
It works fine in CodePen. It needed an additional CSS rule to work in the below snippet. (Don't ask me why!)
$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'><ul></ul></div>"); // Added <ul></ul>
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+" ul"); // added +" ul"
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label ).addClass("ui-menu-item"); // Added the addClass()
);
);
// Actual Code
$(function()
var data = [
label: "annhhx10", category: "Products" ,
label: "annk K12", category: "Products" ,
label: "annttop C13", category: "Products" ,
label: "anders andersson", category: "People" ,
label: "andreas andersson", category: "People" ,
label: "andreas johnson", category: "People"
];
$( "#search" ).catcomplete(
delay: 0,
source: data,
select: function(item, ui) // Added item, ui --- Arguments were missing.
console.log(ui.item.value);
$( "#search" ).val( ui.item.value );
return false;
);
);#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
/* ADDED STYLE */
.ui-autocomplete>li>div>ul
display: block !important;
position: relative !important;
border: 0 !important;
span.ui-menu-icon
display:none !important;
/* ADDED for the SO snippet only !! Not needed on CodePen */
.ui-autocomplete>li
display: inline-block !important;
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<label for="search">Search: </label>
<input id="search">That is widget tweeking I like!
The main mistake was not having a ul as direct parent of your custom li.
Then, Those custom li need the ui-menu-item class in order to be selected...
Lastly, you have to "override" the styling of the nested ul using !important. So they will be displayed as block with a relative position. Incidentally, without border...
And I removed an icon strangely showing...
It works fine in CodePen. It needed an additional CSS rule to work in the below snippet. (Don't ask me why!)
$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'><ul></ul></div>"); // Added <ul></ul>
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+" ul"); // added +" ul"
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label ).addClass("ui-menu-item"); // Added the addClass()
);
);
// Actual Code
$(function()
var data = [
label: "annhhx10", category: "Products" ,
label: "annk K12", category: "Products" ,
label: "annttop C13", category: "Products" ,
label: "anders andersson", category: "People" ,
label: "andreas andersson", category: "People" ,
label: "andreas johnson", category: "People"
];
$( "#search" ).catcomplete(
delay: 0,
source: data,
select: function(item, ui) // Added item, ui --- Arguments were missing.
console.log(ui.item.value);
$( "#search" ).val( ui.item.value );
return false;
);
);#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
/* ADDED STYLE */
.ui-autocomplete>li>div>ul
display: block !important;
position: relative !important;
border: 0 !important;
span.ui-menu-icon
display:none !important;
/* ADDED for the SO snippet only !! Not needed on CodePen */
.ui-autocomplete>li
display: inline-block !important;
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<label for="search">Search: </label>
<input id="search">$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'><ul></ul></div>"); // Added <ul></ul>
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+" ul"); // added +" ul"
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label ).addClass("ui-menu-item"); // Added the addClass()
);
);
// Actual Code
$(function()
var data = [
label: "annhhx10", category: "Products" ,
label: "annk K12", category: "Products" ,
label: "annttop C13", category: "Products" ,
label: "anders andersson", category: "People" ,
label: "andreas andersson", category: "People" ,
label: "andreas johnson", category: "People"
];
$( "#search" ).catcomplete(
delay: 0,
source: data,
select: function(item, ui) // Added item, ui --- Arguments were missing.
console.log(ui.item.value);
$( "#search" ).val( ui.item.value );
return false;
);
);#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
/* ADDED STYLE */
.ui-autocomplete>li>div>ul
display: block !important;
position: relative !important;
border: 0 !important;
span.ui-menu-icon
display:none !important;
/* ADDED for the SO snippet only !! Not needed on CodePen */
.ui-autocomplete>li
display: inline-block !important;
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<label for="search">Search: </label>
<input id="search">$.widget( "custom.catcomplete", $.ui.autocomplete,
_create: function()
this._super();
this.widget().menu( "option", "items", "> :not(.ui-autocomplete-category)" );
,
_renderMenu: function( ul, items )
var that = this,
currentCategory = "";
$.each( items, function( index, item )
var li, submenuUl;
if ( item.category != currentCategory )
var elt = $("<li class='ui-autocomplete-category'>" + item.category + "</li>");
var submenu = $("<div class='submenu "+ item.category +"'><ul></ul></div>"); // Added <ul></ul>
elt.append(submenu);
ul.append(elt);
currentCategory = item.category;
submenuUl = ul.find("."+item.category+" ul"); // added +" ul"
li = that._renderItemData(submenuUl, item );
if ( item.category )
li.attr( "aria-label", item.category + " : " + item.label ).addClass("ui-menu-item"); // Added the addClass()
);
);
// Actual Code
$(function()
var data = [
label: "annhhx10", category: "Products" ,
label: "annk K12", category: "Products" ,
label: "annttop C13", category: "Products" ,
label: "anders andersson", category: "People" ,
label: "andreas andersson", category: "People" ,
label: "andreas johnson", category: "People"
];
$( "#search" ).catcomplete(
delay: 0,
source: data,
select: function(item, ui) // Added item, ui --- Arguments were missing.
console.log(ui.item.value);
$( "#search" ).val( ui.item.value );
return false;
);
);#search
width: 500px;
.ui-autocomplete
display: flex;
width: auto !important;
.ui-autocomplete-category
font-weight: bold;
padding: .2em .4em;
margin: .8em 0 .2em;
line-height: 1.5;
.ui-autocomplete-category ul
padding:0;
.submenu
font-weight: normal;
/* ADDED STYLE */
.ui-autocomplete>li>div>ul
display: block !important;
position: relative !important;
border: 0 !important;
span.ui-menu-icon
display:none !important;
/* ADDED for the SO snippet only !! Not needed on CodePen */
.ui-autocomplete>li
display: inline-block !important;
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.2/jquery-ui.min.js"></script>
<link href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css" rel="stylesheet"/>
<label for="search">Search: </label>
<input id="search">answered Mar 25 at 22:26
Louys Patrice BessetteLouys Patrice Bessette
21.2k4 gold badges23 silver badges48 bronze badges
21.2k4 gold badges23 silver badges48 bronze badges
Thanks a lot it is working as expected. Appreciate it :)
– Nitin Mendiratta
Mar 26 at 13:30
add a comment |
Thanks a lot it is working as expected. Appreciate it :)
– Nitin Mendiratta
Mar 26 at 13:30
Thanks a lot it is working as expected. Appreciate it :)
– Nitin Mendiratta
Mar 26 at 13:30
Thanks a lot it is working as expected. Appreciate it :)
– Nitin Mendiratta
Mar 26 at 13:30
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55346534%2fdisplay-jquery-ui-autocomplete-with-categories-horizontally-and-not-vertically%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown