devbridge / jQuery-Autocomplete

Ajax Autocomplete for jQuery allows you to easily create autocomplete/autosuggest boxes for text input fields
https://www.devbridge.com/sourcery/components/jquery-autocomplete/
Other
3.56k stars 1.66k forks source link

Traying tu use get the Letters with accents matched #712

Closed d00nn1 closed 6 years ago

d00nn1 commented 6 years ago

hello all together first thets the best thing thets i whery long time see and work great i use this codes . i tray to use e like ë and somthinh another things but thet show me this error and sugest don't work (sory my english is not so good ) i'm sorry i add all my code if we solve that, maybe helpe this someone else

Uncaught ReferenceError: _autocompleteCompleted is not defined

          jQuery(function ($) {
              'use strict';
              var countriesArray = $.map(countries, function (value, key) { return { value: value, data: key }; });
              // Initialize ajax autocomplete:
              $('#autocomplete-ajax').autocomplete({
                  // serviceUrl: '/autosuggest/service/url',
                  lookup: countriesArray,
                  lookupFilter: function(suggestion, originalQuery, queryLowerCase) {
                      var re = new RegExp('\\b' + $.Autocomplete.utils.escapeRegExChars(queryLowerCase), 'gi');
                      return re.test(suggestion.value);
                  },
                  onSelect: function(suggestion) {
                      $('#selction-ajax').html('You selected: ' + suggestion.value + ', ' + suggestion.data);
                  },
                  onHint: function (hint) {
                      $('#autocomplete-ajax-x').val(hint);
                  },
                  onInvalidateSelection: function() {
                      $('#selction-ajax').html('You selected: none');

                  }
              });

          var formatRegexp = function(q) {
              q = q.replace(/e/i,'[eéèêëEÉÈÊË]');
              q = q.replace(/a/i,'[aàâäAÀÁÂÃÄÅÆ]');
              q = q.replace(/c/i,'[cçC]');
              q = q.replace(/i/i,'[iïîIÌÍÎÏ]');
              q = q.replace(/o/i,'[oôöÒÓÔÕÖ]');
              q = q.replace(/u/i,'[uüûUÜÛÙÚ]');
              q = q.replace(/y/i,'[yYÿ^yÝ]');
              return q;
          }

          var _autocompleteLookup = function (suggestion, originalQuery, queryLowerCase) {
                  var pattern = '(\\b|^)('+$.Autocomplete.utils.escapeRegExChars(queryLowerCase)+')';
                  pattern = _formatRegexp(pattern);
                  var matcher = new RegExp(pattern);
                  var ret = suggestion.value.toLowerCase().match(matcher);
                  return ret;
          };

          var _autocompleteFormatResult = function (suggestion, currentValue) {
                  var pattern = '(\\b|^)('+$.Autocomplete.utils.escapeRegExChars(currentValue)+')';
                  pattern = _formatRegexp(pattern);
                  return suggestion.value.replace(new RegExp(pattern, 'gi'), '<strong>$1$2<\/strong>');
          };

              // Initialize autocomplete with custom appendTo:
              $('#autocomplete-custom-append').autocomplete({
                 minChars: 1,
                     lookupLimit: 8,
                  lookup: countriesArray,
          noSuggestionNotice: 'Sorry, no matching results',
                  appendTo: '#suggestions-container',
                      onSelect:_autocompleteCompleted.bind(el),*****ERROR SHOW AT THIS POINT****
                      lookupFilter: _autocompleteLookup,
                      formatResult: _autocompleteFormatResult

              });

          });
tkirda commented 6 years ago

Browser is right. _autocompleteCompleted is not defined anywhere. You missed something in your setup.

Also check lodash _.deburr function for replacing accented letters: