From 96b2948813305d8f4510c6054ca6d1fe1767a86c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 1 May 2022 12:01:01 +0200 Subject: [PATCH] AfformGui - Optional reset button for search and submit forms Adds some metadata about what elements belong on what form types, which will now hide the "submit" button as an option for non-submission forms. --- .../admin/Civi/AfformAdmin/AfformAdminMeta.php | 15 +++++++++++++++ .../ang/afGuiEditor/afGuiEntity.component.js | 4 +++- .../ang/afGuiEditor/afGuiSearch.component.js | 8 ++++---- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php b/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php index f195ccaff1..fb04981aaa 100644 --- a/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php +++ b/ext/afform/admin/Civi/AfformAdmin/AfformAdminMeta.php @@ -196,6 +196,7 @@ class AfformAdminMeta { ], 'submit' => [ 'title' => E::ts('Submit Button'), + 'afform_type' => ['form'], 'element' => [ '#tag' => 'button', 'class' => 'af-button btn btn-primary', @@ -206,8 +207,22 @@ class AfformAdminMeta { ], ], ], + 'reset' => [ + 'title' => E::ts('Reset Button'), + 'afform_type' => ['form', 'search'], + 'element' => [ + '#tag' => 'button', + 'class' => 'af-button btn btn-warning', + 'type' => 'reset', + 'crm-icon' => 'fa-undo', + '#children' => [ + ['#text' => E::ts('Reset')], + ], + ], + ], 'fieldset' => [ 'title' => E::ts('Fieldset'), + 'afform_type' => ['form'], 'element' => [ '#tag' => 'fieldset', 'af-fieldset' => NULL, diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js index 001a580b46..f8a051f675 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiEntity.component.js @@ -122,7 +122,9 @@ $scope.elementList.length = 0; $scope.elementTitles.length = 0; _.each(afGui.meta.elements, function(element, name) { - if (!search || _.contains(name, search) || _.contains(element.title.toLowerCase(), search)) { + if ( + (!element.afform_type || _.contains(element.afform_type, 'form')) && + (!search || _.contains(name, search) || _.contains(element.title.toLowerCase(), search))) { var node = _.cloneDeep(element.element); if (name === 'fieldset') { if (!ctrl.editor.allowEntityConfig) { diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiSearch.component.js b/ext/afform/admin/ang/afGuiEditor/afGuiSearch.component.js index 0247479f76..d6f93f6c07 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiSearch.component.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiSearch.component.js @@ -157,11 +157,11 @@ $scope.elementList.length = 0; $scope.elementTitles.length = 0; _.each(afGui.meta.elements, function(element, name) { - if (!search || _.contains(name, search) || _.contains(element.title.toLowerCase(), search)) { + if ( + (!element.afform_type || _.contains(element.afform_type, 'search')) && + (!search || _.contains(name, search) || _.contains(element.title.toLowerCase(), search)) + ) { var node = _.cloneDeep(element.element); - if (name === 'fieldset') { - return; - } $scope.elementList.push(node); $scope.elementTitles.push(element.title); } -- 2.25.1