[BUGFIX] Call autocomplete only if field is available 11/56211/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Fri, 16 Mar 2018 11:07:38 +0000 (12:07 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 16 Mar 2018 11:26:57 +0000 (12:26 +0100)
Resolves: #84335
Related: #82592
Related: #82969
Releases: master
Change-Id: I6afa442fdfb86e2ffeff0b3c39c12ed2c7e8df6c
Reviewed-on: https://review.typo3.org/56211
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Tested-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
typo3/sysext/backend/Resources/Private/TypeScript/LiveSearch.ts
typo3/sysext/backend/Resources/Public/JavaScript/LiveSearch.js

index 12acc50..e71b8b1 100644 (file)
@@ -173,7 +173,6 @@ class LiveSearch {
 
   private registerEvents(): void {
     const $searchField = $(Identifiers.searchFieldSelector);
-    const $autocompleteContainer = $('.' + $searchField.autocomplete().options.containerClass);
 
     $(Identifiers.containerSelector).on('click', '.t3js-live-search-show-all', (evt: JQueryEventObject): void => {
       evt.preventDefault();
@@ -182,6 +181,7 @@ class LiveSearch {
       $searchField.val('').trigger('change');
     });
     if ($searchField.length) {
+      const $autocompleteContainer = $('.' + $searchField.autocomplete().options.containerClass);
       $autocompleteContainer.on('click.autocomplete', '.dropdown-list-link', (evt: JQueryEventObject): void => {
         evt.preventDefault();
 
index c02a5ea..1b74d98 100644 (file)
@@ -10,4 +10,4 @@
  *
  * The TYPO3 project - inspiring people to share!
  */
-define(["require","exports","jquery","./Viewport","./Icons","jquery/autocomplete","TYPO3/CMS/Backend/jquery.clearable"],function(e,t,o,a,r){"use strict";var n,l;return(l=n||(n={})).containerSelector="#typo3-cms-backend-backend-toolbaritems-livesearchtoolbaritem",l.toolbarItem=".t3js-toolbar-item-search",l.dropdownToggle=".t3js-toolbar-search-dropdowntoggle",l.searchFieldSelector=".t3js-topbar-navigation-search-field",l.formSelector=".t3js-topbar-navigation-search",new(function(){function e(){var e=this;this.url=TYPO3.settings.ajaxUrls.livesearch,a.Topbar.Toolbar.registerEvent(function(){e.registerAutocomplete(),e.registerEvents(),o(n.toolbarItem).removeAttr("style"),o(n.searchFieldSelector).clearable({onClear:function(){o(n.toolbarItem).hasClass("open")&&o(n.dropdownToggle).dropdown("toggle")}})})}return e.prototype.registerAutocomplete=function(){o(n.searchFieldSelector).autocomplete({serviceUrl:this.url,paramName:"q",dataType:"json",minChars:2,width:"100%",groupBy:"typeLabel",containerClass:n.toolbarItem.substr(1,n.toolbarItem.length),appendTo:n.containerSelector+" .dropdown-menu",forceFixPosition:!1,preserveInput:!0,showNoSuggestionNotice:!0,triggerSelectOnValidInput:!1,preventBadQueries:!1,noSuggestionNotice:'<h3 class="dropdown-headline">'+TYPO3.lang.liveSearch_listEmptyText+"</h3><p>"+TYPO3.lang.liveSearch_helpTitle+"</p><hr><p>"+TYPO3.lang.liveSearch_helpDescription+"<br>"+TYPO3.lang.liveSearch_helpDescriptionPages+"</p>",transformResult:function(e){return{suggestions:o.map(e,function(e){return{value:e.title,data:e}})}},formatGroup:function(e,t,o){var a="";return o>0&&(a="<hr>"),a+'<h3 class="dropdown-headline">'+t+"</h3>"},formatResult:function(e){return'<div class="dropdown-table"><div class="dropdown-table-row"><div class="dropdown-table-column dropdown-table-icon">'+e.data.iconHTML+'</div><div class="dropdown-table-column dropdown-table-title"><a class="dropdown-table-title-ellipsis dropdown-list-link" href="#" data-pageid="'+e.data.pageId+'" data-target="'+e.data.editLink+'">'+e.data.title+"</a></div></div></div>"},onSearchStart:function(){var e=o(n.toolbarItem);e.hasClass("loading")||(e.addClass("loading"),r.getIcon("spinner-circle-light",r.sizes.small,"",r.states.default,r.markupIdentifiers.inline).done(function(t){e.find(".icon-apps-toolbar-menu-search").replaceWith(t)}))},onSearchComplete:function(){var e=o(n.toolbarItem),t=o(n.searchFieldSelector);!e.hasClass("open")&&t.val().length>1&&(o(n.dropdownToggle).dropdown("toggle"),t.focus()),e.hasClass("loading")&&(e.removeClass("loading"),r.getIcon("apps-toolbar-menu-search",r.sizes.small,"",r.states.default,r.markupIdentifiers.inline).done(function(t){e.find(".icon-spinner-circle-light").replaceWith(t)}))},beforeRender:function(e){e.append('<hr><div><a href="#" class="btn btn-primary pull-right t3js-live-search-show-all">'+TYPO3.lang.liveSearch_showAllResults+"</a></div>"),o(n.toolbarItem).hasClass("open")||(o(n.dropdownToggle).dropdown("toggle"),o(n.searchFieldSelector).focus())},onHide:function(){o(n.toolbarItem).hasClass("open")&&o(n.dropdownToggle).dropdown("toggle")}})},e.prototype.registerEvents=function(){var e=o(n.searchFieldSelector),t=o("."+e.autocomplete().options.containerClass);o(n.containerSelector).on("click",".t3js-live-search-show-all",function(t){t.preventDefault(),TYPO3.ModuleMenu.App.showModule("web_list","id=0&search_levels=-1&search_field="+encodeURIComponent(e.val())),e.val("").trigger("change")}),e.length&&t.on("click.autocomplete",".dropdown-list-link",function(t){t.preventDefault();var a=o(t.currentTarget);top.jump(a.data("target"),"web_list","web",a.data("pageid")),e.val("").trigger("change")}),o(n.formSelector).on("submit",function(e){e.preventDefault()})},e}())});
\ No newline at end of file
+define(["require","exports","jquery","./Viewport","./Icons","jquery/autocomplete","TYPO3/CMS/Backend/jquery.clearable"],function(e,t,o,a,r){"use strict";var n,l;return(l=n||(n={})).containerSelector="#typo3-cms-backend-backend-toolbaritems-livesearchtoolbaritem",l.toolbarItem=".t3js-toolbar-item-search",l.dropdownToggle=".t3js-toolbar-search-dropdowntoggle",l.searchFieldSelector=".t3js-topbar-navigation-search-field",l.formSelector=".t3js-topbar-navigation-search",new(function(){function e(){var e=this;this.url=TYPO3.settings.ajaxUrls.livesearch,a.Topbar.Toolbar.registerEvent(function(){e.registerAutocomplete(),e.registerEvents(),o(n.toolbarItem).removeAttr("style"),o(n.searchFieldSelector).clearable({onClear:function(){o(n.toolbarItem).hasClass("open")&&o(n.dropdownToggle).dropdown("toggle")}})})}return e.prototype.registerAutocomplete=function(){o(n.searchFieldSelector).autocomplete({serviceUrl:this.url,paramName:"q",dataType:"json",minChars:2,width:"100%",groupBy:"typeLabel",containerClass:n.toolbarItem.substr(1,n.toolbarItem.length),appendTo:n.containerSelector+" .dropdown-menu",forceFixPosition:!1,preserveInput:!0,showNoSuggestionNotice:!0,triggerSelectOnValidInput:!1,preventBadQueries:!1,noSuggestionNotice:'<h3 class="dropdown-headline">'+TYPO3.lang.liveSearch_listEmptyText+"</h3><p>"+TYPO3.lang.liveSearch_helpTitle+"</p><hr><p>"+TYPO3.lang.liveSearch_helpDescription+"<br>"+TYPO3.lang.liveSearch_helpDescriptionPages+"</p>",transformResult:function(e){return{suggestions:o.map(e,function(e){return{value:e.title,data:e}})}},formatGroup:function(e,t,o){var a="";return o>0&&(a="<hr>"),a+'<h3 class="dropdown-headline">'+t+"</h3>"},formatResult:function(e){return'<div class="dropdown-table"><div class="dropdown-table-row"><div class="dropdown-table-column dropdown-table-icon">'+e.data.iconHTML+'</div><div class="dropdown-table-column dropdown-table-title"><a class="dropdown-table-title-ellipsis dropdown-list-link" href="#" data-pageid="'+e.data.pageId+'" data-target="'+e.data.editLink+'">'+e.data.title+"</a></div></div></div>"},onSearchStart:function(){var e=o(n.toolbarItem);e.hasClass("loading")||(e.addClass("loading"),r.getIcon("spinner-circle-light",r.sizes.small,"",r.states.default,r.markupIdentifiers.inline).done(function(t){e.find(".icon-apps-toolbar-menu-search").replaceWith(t)}))},onSearchComplete:function(){var e=o(n.toolbarItem),t=o(n.searchFieldSelector);!e.hasClass("open")&&t.val().length>1&&(o(n.dropdownToggle).dropdown("toggle"),t.focus()),e.hasClass("loading")&&(e.removeClass("loading"),r.getIcon("apps-toolbar-menu-search",r.sizes.small,"",r.states.default,r.markupIdentifiers.inline).done(function(t){e.find(".icon-spinner-circle-light").replaceWith(t)}))},beforeRender:function(e){e.append('<hr><div><a href="#" class="btn btn-primary pull-right t3js-live-search-show-all">'+TYPO3.lang.liveSearch_showAllResults+"</a></div>"),o(n.toolbarItem).hasClass("open")||(o(n.dropdownToggle).dropdown("toggle"),o(n.searchFieldSelector).focus())},onHide:function(){o(n.toolbarItem).hasClass("open")&&o(n.dropdownToggle).dropdown("toggle")}})},e.prototype.registerEvents=function(){var e=o(n.searchFieldSelector);(o(n.containerSelector).on("click",".t3js-live-search-show-all",function(t){t.preventDefault(),TYPO3.ModuleMenu.App.showModule("web_list","id=0&search_levels=-1&search_field="+encodeURIComponent(e.val())),e.val("").trigger("change")}),e.length)&&o("."+e.autocomplete().options.containerClass).on("click.autocomplete",".dropdown-list-link",function(t){t.preventDefault();var a=o(t.currentTarget);top.jump(a.data("target"),"web_list","web",a.data("pageid")),e.val("").trigger("change")});o(n.formSelector).on("submit",function(e){e.preventDefault()})},e}())});
\ No newline at end of file