Well, one of the approaches may be the following:
$("form#busca #campo-busca").autocomplete({
minLength: 3,
source: 'autocomplete.php',
/**
* Sugestão de uma das possíveis soluções.
*/
select: function( event, ui ) {
/**
* Considerando que podemos acessar o valor assim: ui.item.value
*/
$("form#busca #campo-busca").val( ui.item.value );
// ou
$("form#busca #campo-busca").html( ui.item.value );
return false;
},
html: true
});
NOTE: interesting to analyze the possibility of using the resources in a way to reuse. This way think about creating the component inside a plugin [Jonathan Chaffer, Karl Swedberg - 2013, ___ 8 - Developing Plugins, 234 p.] and using as a $.widget(){}.
the plugin file: app-your-plugin.js
/*@!
* @auth: Paulo Sérgio da Silva
* @email: [email protected]
* @plugin: app-seu-plugin.js
* @description: O objetivo de centralizar as funções genéricas para o
* carregamento e apresentação do autocompletar em ????????.
*
* Autocompletar Categoria v1.0.0 (http://www.??????/)
* Copyright 2011-2015 ????, Pub.
* Licensed under MIT ()
*/
if (typeof jQuery === 'undefined') {
throw new Error('Component Type Fields\'s JavaScript requires jQuery')
}
/**
* Criando o plugin
*/
(function($){
var SeuPlugin = function(){
this.alertTestPlugin = function(){
console.log("alertTestPlugin: Testando o plugin jQuery!");
alert("alertTestPlugin: Testando o plugin jQuery!");
return false;
};
this.createWidget = function() {
/** Criando do widget */
$.widget( "custom.seuComponenteAutocompletar", $.ui.autocomplete, {
_create: function() {
//Implementar o comportamento de seu interesse
},
_renderMenu: function( ul, items ) {
//Implementar a aparência de seu meu
}
});
}
};
$.SeuPlugin = new SeuPlugin();
$.SeuPlugin.prototype = SeuPlugin;
})(jQuery);
/**
*
*/
$.SeuPlugin.createWidget();
Load your plugin:
<link href="https://code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!-- Carregar o seu plugin -->
<script src="../plugins/PATH_PARA_SEU_PLUGIN/app-seu-plugin.js"></script>
Using its component:
$("form#busca #campo-busca").seuComponenteAutocompletar({
delay: 0,
minLength: 3,
source: 'autocomplete.php',
html: true
});
Reference:
[Jonathan Chaffer, Karl Swedberg - 2013], Copyright 2013 Packt Publishing, Learning jQuery Fourth Edition: Better Interaction, design, and web Development with simple Javascript Techniques. Available at: < https://www.packtpub.com/web-development/learning-jquery-fourth-edition >. Accessed: Nov 25, 2017.
[jqueryui], Autocomplete #Categories: jQuery User interface - Autocomplete. Available in: < https://jqueryui.com/autocomplete/#Categories >. Accessed: Nov 25, 2017.
Aryana Valcanaia, check if you remove tags: From $result[] = "<b>Category</b> {$nameCategory['name']}"; For $result[] = "Category - {$nameCategory['name']}";.
– pss1suporte
@pss1support Hi! Yes, if I take the tags away, the input is not presented. The problem is that I need to keep the formatting of the first image :/
– Aryana Valcanaia
@Aryanavalcanaia already tried to use the method _renderItem ?
– NoobSaibot
hi @wmsouza! I tried yes, I don’t know if I didn’t implement it right or I couldn’t implement it, but it didn’t work :/ I believe that with it I need to return an array within my $result[] passing a value to be displayed by the input and another by the search results. I tried everything that is way and did not roll. I also can not find example as what I need :(
– Aryana Valcanaia