|
1 | 1 | /** |
2 | | -* Ajax Autocomplete for jQuery, version 1.2.3 |
| 2 | +* Ajax Autocomplete for jQuery, version 1.2.4 |
3 | 3 | * (c) 2013 Tomas Kirda |
4 | 4 | * |
5 | 5 | * Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license. |
|
89 | 89 | onSearchComplete: noop, |
90 | 90 | containerClass: 'autocomplete-suggestions', |
91 | 91 | tabDisabled: false, |
| 92 | + dataType : 'text', |
92 | 93 | lookupFilter: function (suggestion, originalQuery, queryLowerCase) { |
93 | 94 | return suggestion.value.toLowerCase().indexOf(queryLowerCase) !== -1; |
94 | 95 | }, |
|
179 | 180 |
|
180 | 181 | // Listen for click event on suggestions list: |
181 | 182 | container.on('click', suggestionSelector, function () { |
182 | | - that.select($(this).data('index')); |
| 183 | + that.select($(this).data('index'), false); |
183 | 184 | }); |
184 | 185 |
|
185 | 186 | that.fixPosition(); |
|
243 | 244 | } |
244 | 245 |
|
245 | 246 | offset = that.el.offset(); |
246 | | - |
| 247 | + |
247 | 248 | $(that.suggestionsContainer).css({ |
248 | 249 | top: (offset.top + that.el.outerHeight()) + 'px', |
249 | 250 | left: offset.left + 'px' |
|
297 | 298 | that.hide(); |
298 | 299 | return; |
299 | 300 | } |
300 | | - that.select(that.selectedIndex); |
| 301 | + that.select(that.selectedIndex, e.keyCode === keys.RETURN); |
301 | 302 | if (e.keyCode === keys.TAB && this.options.tabDisabled === false) { |
302 | 303 | return; |
303 | 304 | } |
|
359 | 360 | return; |
360 | 361 | } |
361 | 362 |
|
362 | | - if (q === '' || q.length < that.options.minChars) { |
| 363 | + if (q.length < that.options.minChars) { |
363 | 364 | that.hide(); |
364 | 365 | } else { |
365 | 366 | that.getSuggestions(q); |
|
406 | 407 | url: options.serviceUrl, |
407 | 408 | data: options.params, |
408 | 409 | type: options.type, |
409 | | - dataType: 'text' |
| 410 | + dataType: options.dataType |
410 | 411 | }).done(function (txt) { |
411 | 412 | that.processResponse(txt); |
412 | 413 | options.onSearchComplete.call(that.element, q); |
|
476 | 477 |
|
477 | 478 | processResponse: function (text) { |
478 | 479 | var that = this, |
479 | | - response = $.parseJSON(text); |
| 480 | + response = typeof text == 'string' ? $.parseJSON(text) : text; |
480 | 481 |
|
481 | 482 | response.suggestions = that.verifySuggestionsFormat(that.options.transformResult(response)); |
482 | 483 |
|
|
515 | 516 | return null; |
516 | 517 | }, |
517 | 518 |
|
518 | | - select: function (i) { |
| 519 | + select: function (i, shouldIgnoreNextValueChange) { |
519 | 520 | var that = this, |
520 | 521 | selectedValue = that.suggestions[i]; |
521 | 522 |
|
522 | 523 | if (selectedValue) { |
523 | 524 | that.el.val(selectedValue); |
524 | | - that.ignoreValueChange = true; |
| 525 | + that.ignoreValueChange = shouldIgnoreNextValueChange; |
525 | 526 | that.hide(); |
526 | 527 | that.onSelect(i); |
527 | 528 | } |
|
0 commit comments