Last active
April 15, 2018 17:01
-
-
Save JunaidQadirB/c612b3f9325e66ea51200de83d3d2885 to your computer and use it in GitHub Desktop.
Customized jQuery UI Autocomplete Widget: List Items with description
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("#tags").autocomplete({ | |
source : availableTags, | |
select : function(event, ui) { | |
itemTitleDesc = split(ui.item.value); | |
if (is_array(itemTitleDesc)) { | |
itemTitle = itemTitleDesc[0]; | |
if (itemTitleDesc.length > 1) { | |
itemDesc = itemTitleDesc[1]; | |
itemDesc = itemDesc.replace(")", ""); | |
} | |
ui.item.value = itemTitle; | |
} | |
} | |
}).data("autocomplete")._renderItem = function(ul, item) { | |
itemTitleDesc = split(item.value); | |
var desc = ""; | |
if (is_array(itemTitleDesc)) { | |
itemTitle = itemTitleDesc[0]; | |
if (itemTitleDesc.length > 1) { | |
itemDesc = itemTitleDesc[1]; | |
itemDesc = itemDesc.replace(")", ""); | |
desc = '<br/><span><small>' + itemDesc + | |
'</small></span>'; | |
} | |
var itemContent = '<span><strong>' + itemTitle + | |
'</strong></span>' + desc; | |
return $("<li></li>") | |
.data("item.autocomplete", item) | |
.append($("<a></a>").html(itemContent)) | |
.appendTo(ul); | |
} else { | |
return $("<li></li>") | |
.data("item.autocomplete", item) | |
.append($("<a></a>").html(item.label)) | |
.appendTo(ul); | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function is_array(input) { | |
$ret = typeof (input) == 'object' && (input instanceof Array); | |
return $ret; | |
} | |
function split(val) { | |
return val.split("("); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* jquery.ui.autocomplete.js | |
* Line Number: 449 | |
* | |
*/ | |
_renderItem: function (ul, item) { | |
return $("<li></li>") | |
.data("item.autocomplete", item) | |
.append($("<a></a>").text(item.label)) | |
.appendTo(ul); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_renderItem = function (ul, item) { | |
itemTitleDesc = split(item.value); | |
var desc = ""; | |
if (is_array(itemTitleDesc)) { | |
itemTitle = itemTitleDesc[0]; | |
if (itemTitleDesc.length > 1) { | |
itemDesc = itemTitleDesc[1]; | |
itemDesc = itemDesc.replace(")", ""); | |
desc = '<br/><span><small>' + itemDesc + '</small></span>'; | |
} | |
var itemContent = '<span><strong>' + itemTitle | |
+ '</strong></span>' + desc; | |
return $("<li></li>").data("item.autocomplete", item).append( | |
$("<a></a>").html(itemContent)).appendTo(ul); | |
} else { | |
return $("<li></li>").data("item.autocomplete", item).append( | |
$("<a></a>").html(item.label)).appendTo(ul); | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select : function (event, ui) { | |
itemTitleDesc = split(ui.item.value); | |
if (is_array(itemTitleDesc)) { | |
itemTitle = itemTitleDesc[0]; | |
if (itemTitleDesc.length > 1) { | |
itemDesc = itemTitleDesc[1]; | |
itemDesc = itemDesc.replace(")", ""); | |
} | |
ui.item.value = itemTitle; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment