Advertisement
EvaldoMaciel

Autocomplete

May 26th, 2020
1,688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                                 <button class="btn btn-primary" id="btnAddPapel" onclick="adicionaPapeis();"><i class="fluigicon fluigicon-plus icon-xs"></i> Adicionar Partes</button>
  2.  
  3.  
  4. function inicializarAutoComplete(nomeDoCampo) {
  5.     var operacoesAutoComplete = [];
  6.     if (operacoesAutoComplete[nomeDoCampo] !== undefined) {
  7.         operacoesAutoComplete[nomeDoCampo].destroy();
  8.         operacoesAutoComplete[nomeDoCampo] = undefined;
  9.     }
  10.     var campos = ["colleagueName", "colleaguePK.colleagueId"];
  11.     var operacoes = DatasetFactory.getDataset("colleague", campos, null, null).values;
  12.     funcTemp = [];
  13.     for (i = 0; i < operacoes.length; i++) {
  14.         funcTemp.push(operacoes[i]["colleaguePK.colleagueId"] + "-" + operacoes[i]["colleagueName"]);
  15.     }
  16.  
  17.     operacoesAutoComplete[nomeDoCampo] = FLUIGC.autocomplete(nomeDoCampo, {
  18.         source: substringMatcher(funcTemp),
  19.         name: 'funcionarios',
  20.         minLength: 5,
  21.         displayKey: 'description',
  22.         allowDuplicates: false,
  23.         hint: true,
  24.         tagClass: 'tag-gray',
  25.         type: 'autocomplete'
  26.     });
  27. }
  28.  
  29.  
  30. function substringMatcher(strs) {
  31.     return function findMatches(q, cb) {
  32.         var matches, substrRegex;
  33.         matches = [];
  34.         substrRegex = new RegExp(q, 'i');
  35.         $.each(strs, function (i, str) { if (substrRegex.test(str)) { matches.push({ description: str }); } }); cb(matches);
  36.     };
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement