[Rt-commit] rt branch 5.0/bootstrap-select-live-search created. rt-5.0.3-214-g8e79427940

BPS Git Server git at git.bestpractical.com
Tue Dec 27 21:43:32 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 5.0/bootstrap-select-live-search has been created
        at  8e794279400d887a1d72a32c2ed1e377112eaa88 (commit)

- Log -----------------------------------------------------------------
commit 8e794279400d887a1d72a32c2ed1e377112eaa88
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Sat Dec 17 05:14:35 2022 +0800

    Automatically enable live search for selects that have 10 or more options
    
    If the select already has data-live-search specified, leave it alone.

diff --git a/share/static/js/assets.js b/share/static/js/assets.js
index a70a4dcd62..6eba4c09d5 100644
--- a/share/static/js/assets.js
+++ b/share/static/js/assets.js
@@ -8,7 +8,7 @@ jQuery(function() {
 
         // We need to refresh the select picker plugin on AJAX calls
         // since the plugin only runs on page load.
-        jQuery('.selectpicker').selectpicker('refresh');
+        refreshSelectpicker();
     };
 
     jQuery(".ticket-assets form").submit(function(){
diff --git a/share/static/js/cascaded.js b/share/static/js/cascaded.js
index b73b99f2fb..d9596cbd5d 100644
--- a/share/static/js/cascaded.js
+++ b/share/static/js/cascaded.js
@@ -80,6 +80,6 @@ function filter_cascade_select (select, complete_select, vals) {
     }
 
     if ( jQuery(select).closest('div.bootstrap-select').length ) {
-        jQuery(select).selectpicker('refresh');
+        refreshSelectpicker(jQuery(select));
     }
 }
diff --git a/share/static/js/lifecycleui-editor.js b/share/static/js/lifecycleui-editor.js
index e31757a458..c61412dfce 100644
--- a/share/static/js/lifecycleui-editor.js
+++ b/share/static/js/lifecycleui-editor.js
@@ -360,7 +360,7 @@ jQuery(function () {
                     jQuery(item).val(element[item.name]);
                 }
                 self.editing_node = element;
-                jQuery('.selectpicker').selectpicker('refresh');
+                refreshSelectpicker();
             }
             else {
                 var name = document.getElementsByName('name')[0].value;
diff --git a/share/static/js/util.js b/share/static/js/util.js
index a965479375..bd14574530 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -44,7 +44,7 @@ var showModal = function(html) {
 
     // We need to refresh the select picker plugin on AJAX calls
     // since the plugin only runs on page load.
-    jQuery('.selectpicker').selectpicker('refresh');
+    refreshSelectpicker();
     RT.Autocomplete.bind(modal);
 };
 
@@ -1315,6 +1315,8 @@ jQuery(function () {
             });
         });
     });
+
+    updateSelectpickerLiveSearch();
 });
 
 // focus jquery object in window, only moving the screen when necessary
@@ -1406,3 +1408,18 @@ function toggleTransactionDetails () {
 
     return false;
 }
+
+function updateSelectpickerLiveSearch (element) {
+    element ||= jQuery('.selectpicker');
+    element.filter(':not([data-live-search])').each(function() {
+        // Unlike WebPath, SelectLiveSearchLimit is not a real RT config, but
+        // can also be customized in Data callback of /Elements/JavascriptConfig
+        jQuery(this).attr('data-live-search', jQuery(this).find('option').length >= (RT.Config.SelectLiveSearchLimit || 10) ? true : false );
+    });
+}
+
+function refreshSelectpicker (element) {
+    element ||= jQuery('.selectpicker');
+    updateSelectpickerLiveSearch(element);
+    element.selectpicker('refresh');
+}

-----------------------------------------------------------------------


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list