dev/core#4254 - Add autoOpen feature to SearchKit 'addNew' button
authorcolemanw <coleman@civicrm.org>
Wed, 7 Jun 2023 19:41:43 +0000 (15:41 -0400)
committercolemanw <coleman@civicrm.org>
Wed, 7 Jun 2023 19:41:43 +0000 (15:41 -0400)
ext/civicrm_admin_ui/managed/SavedSearch_Administer_Custom_Fields.mgd.php
ext/civicrm_admin_ui/managed/SavedSearch_Administer_ProfileFields.mgd.php
ext/search_kit/ang/crmSearchDisplay/traits/searchDisplayBaseTrait.service.js

index e53e178a8d8135a385ac95c667611a95df1cd609..e9c234c83797a6f57e3b39917f9ef7e84b6c65e2 100644 (file)
@@ -201,6 +201,7 @@ return [
             'path' => 'civicrm/admin/custom/group/field/add?reset=1&action=add&gid=[custom_group_id]',
             'text' => E::ts('Add Custom Field'),
             'icon' => 'fa-plus',
+            'autoOpen' => TRUE,
           ],
           'placeholder' => 5,
         ],
index e7b55d55dc8c58660a797208600e08a612d1ab1b..277e1ee569c18d055eff577a0177b5bdcf572c4f 100644 (file)
@@ -174,6 +174,7 @@ return [
             'path' => 'civicrm/admin/uf/group/field/add?reset=1&action=add&gid=[uf_group_id]',
             'text' => E::ts('Add Field'),
             'icon' => 'fa-plus',
+            'autoOpen' => TRUE,
           ],
           'cssRules' => [
             [
index f4543e8ea08cdf8c2b8bfc7339b6d06d54b576bd..d40b30ce6b210d4e55090334e03e549a7df10686 100644 (file)
                 ctrl.rowCount = result.count;
               });
             }
+            // If there are no results on initial load, open the "addNew" link if configured as "autoOpen"
+            if (!ctrl.results.length && requestId === 1 && ctrl.settings.addButton && ctrl.settings.addButton.autoOpen) {
+              CRM.loadForm(ctrl.getButtonUrl())
+                .on('crmFormSuccess', function() {
+                  ctrl.rowCount = null;
+                  ctrl.getResultsPronto();
+                });
+            }
           }
           _.each(ctrl.onPostRun, function(callback) {
             callback.call(ctrl, ctrl.results, 'success', editedRow);