|
65 | 65 | inputWrapper: '<div class="mage-suggest"><div class="mage-suggest-inner"></div></div>', |
66 | 66 | dropdownWrapper: '<div class="mage-suggest-dropdown"></div>', |
67 | 67 | preventClickPropagation: true, |
68 | | - currentlySelected: null |
| 68 | + currentlySelected: null, |
| 69 | + submitInputOnEnter: true |
69 | 70 | }, |
70 | 71 |
|
71 | 72 | /** |
|
79 | 80 | label: '' |
80 | 81 | }; |
81 | 82 | this.templates = {}; |
82 | | - |
83 | 83 | this._renderedContext = null; |
84 | 84 | this._selectedItem = this._nonSelectedItem; |
85 | 85 | this._control = this.options.controls || {}; |
|
312 | 312 | click: this.search |
313 | 313 | }, this.options.events)); |
314 | 314 |
|
| 315 | + this._bindSubmit(); |
315 | 316 | this._bindDropdown(); |
316 | 317 | }, |
317 | 318 |
|
318 | 319 | /** |
319 | | - * @param {Object} event - event object |
| 320 | + * @param {Object} event |
320 | 321 | * @private |
321 | 322 | */ |
322 | 323 | _toggleEnter: function (event) { |
323 | 324 | var suggestList, |
324 | 325 | activeItems, |
325 | 326 | selectedItem; |
326 | 327 |
|
| 328 | + if (!this.options.submitInputOnEnter) { |
| 329 | + event.preventDefault(); |
| 330 | + } |
| 331 | + |
327 | 332 | suggestList = $(event.currentTarget.parentNode).find('ul').first(); |
328 | 333 | activeItems = suggestList.find('._active'); |
329 | 334 |
|
|
333 | 338 | if (selectedItem.find('a') && selectedItem.find('a').attr('href') !== undefined) { |
334 | 339 | window.location = selectedItem.find('a').attr('href'); |
335 | 340 | event.preventDefault(); |
336 | | - |
337 | | - return false; |
338 | 341 | } |
339 | 342 | } |
340 | 343 | }, |
341 | 344 |
|
| 345 | + /** |
| 346 | + * Bind handlers for submit on enter |
| 347 | + * @private |
| 348 | + */ |
| 349 | + _bindSubmit: function () { |
| 350 | + this.element.parents('form').on('submit', function (event) { |
| 351 | + if (!this.submitInputOnEnter) { |
| 352 | + event.preventDefault(); |
| 353 | + } |
| 354 | + }); |
| 355 | + }, |
| 356 | + |
342 | 357 | /** |
343 | 358 | * @param {Object} e - event object |
344 | 359 | * @private |
|
465 | 480 | } |
466 | 481 |
|
467 | 482 | if (this._trigger('beforeselect', e || null, { |
468 | | - item: this._focused |
469 | | - }) === false) { |
| 483 | + item: this._focused |
| 484 | + }) === false) { |
470 | 485 | return; |
471 | 486 | } |
472 | 487 | this._selectItem(e); |
|
701 | 716 | if ($.isArray(o.source)) { |
702 | 717 | response(this.filter(o.source, term)); |
703 | 718 | } else if ($.type(o.source) === 'string') { |
704 | | - if (this._xhr) { |
705 | | - this._xhr.abort(); |
706 | | - } |
707 | 719 | ajaxData = {}; |
708 | 720 | ajaxData[this.options.termAjaxArgument] = term; |
709 | 721 |
|
|
729 | 741 | _abortSearch: function () { |
730 | 742 | this.element.removeClass(this.options.loadingClass); |
731 | 743 | clearTimeout(this._searchTimeout); |
732 | | - |
733 | | - if (this._xhr) { |
734 | | - this._xhr.abort(); |
735 | | - } |
736 | 744 | }, |
737 | 745 |
|
738 | 746 | /** |
|
905 | 913 | '<li class="mage-suggest-search-field" data-role="parent-choice-element"><' + |
906 | 914 | 'label class="mage-suggest-search-label"></label></li></ul>', |
907 | 915 | choiceTemplate: '<li class="mage-suggest-choice button"><div><%- text %></div>' + |
908 | | - '<span class="mage-suggest-choice-close" tabindex="-1" ' + |
909 | | - 'data-mage-init=\'{"actionLink":{"event":"removeOption"}}\'></span></li>', |
| 916 | + '<span class="mage-suggest-choice-close" tabindex="-1" ' + |
| 917 | + 'data-mage-init=\'{"actionLink":{"event":"removeOption"}}\'></span></li>', |
910 | 918 | selectedClass: 'mage-suggest-selected' |
911 | 919 | }, |
912 | 920 |
|
|
0 commit comments