Typeahead with accentuation

Asked

Viewed 111 times

1

I created a small application that uses typeahead to search. I have registered people with accentuated names and to find them I need to write the absolute name (with accent). I need to find a person with for example the name "Felícia" without having to add the accent in í. the code I’m using is as follows::

$.getJSON("{{ route('getRamaisJson') }}", function(data) {
				var jsonData = data;
				var dataSource = new Bloodhound({
					datumTokenizer: Bloodhound.tokenizers.obj.whitespace('id', 'nome', 'ramal', 'imagem_link', 'funcao', 'departamento', 'email', 'aniversario'),
					queryTokenizer: Bloodhound.tokenizers.whitespace,
					local: jsonData
				});

				dataSource.initialize();

				$('.typeahead').typeahead({
					minLength: 0,
					highlight: true
				}, {
					name: 'search-itens-list',
					// ao clicar em um resultado da busca o que vai ser adicionado no campo de pesquisa
					display: function(item){ return item.nome},
					source: dataSource.ttAdapter(),
					templates: {
						// se não houver resultados com base na busca exibir o seguinte template
						empty: ['<div class="empty">Nenhuma informação encontrada</div>'].join('\n'),
						suggestion: function (data) {

							feliz_niver = "";
							ramal = "";
							email = "";
							link = window.location.href + "/visualizar/" + data.id;

							if(data.ramal)
							{
								// formata o template dos itens que são exibidos na busca
								ramal = ' - <small><strong>Ramal:</strong> ' + data.ramal;
							}

							if(data.email)
							{
								// formata o template dos itens que são exibidos na busca
								email = '</small></p><p><strong>E-mail:</strong> ' + data.email;
							}

							if(data.aniversario)
							{
								// formata o template dos itens que são exibidos na busca
								feliz_niver = '<h5 style="color:#0273BD "><span class="glyphicon glyphicon-gift" aria-hidden="true" style="color:#318255" ></span> Feliz Aniversário!!!</h5>';
							}

							return '<ul><li><a href="' + link + '"<p><strong>Nome:</strong> ' + data.nome + ramal + email + '</p><p><strong>Departamento:</strong> ' + data.departamento + '</small></p>' + feliz_niver + '<img src="' + data.imagem_link + '" alt="' + data.nome + '"></li>';
						}
					}
				});
			});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

library: https://github.com/twitter/typeahead.js/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.