From 72efe79ce4d2e293a3a7efb0d81fdf63c72e4c29 Mon Sep 17 00:00:00 2001 From: Bram Velthoven <bram.velthoven@finalist.nl> Date: Mon, 7 Apr 2025 14:13:42 +0200 Subject: [PATCH 1/3] Issue #3493640 by bram.velthoven: Boolean field should not show "N/A" option when set to required --- js/conditional_fields.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/js/conditional_fields.js b/js/conditional_fields.js index 61e0bbd..1a14214 100644 --- a/js/conditional_fields.js +++ b/js/conditional_fields.js @@ -120,6 +120,8 @@ .on('state:required', (e) => { if (e.trigger) { const fieldsSupportingRequired = $(e.target).find('input, textarea'); + // Option 'N/A' etc should not be present when field is required. + const requiredNoneOption = fieldsSupportingRequired.filter('[id*="component-none"]').parent(); const legends = $(e.target).find('legend'); const legendsspan = $(e.target).find('legend span'); const labels = $(e.target).find( @@ -139,6 +141,9 @@ if (tabs.length !== 0) { tab.find('strong').addClass('form-required'); } + if (requiredNoneOption.length !== 0) { + requiredNoneOption.hide(); + } } else { labels.addClass('form-required'); } @@ -152,6 +157,9 @@ if (tabs.length !== 0) { tab.find('strong').removeClass('form-required'); } + if (requiredNoneOption.length !== 0) { + requiredNoneOption.show(); + } } else { labels.removeClass('form-required'); } -- GitLab From 14ea0d4f548f546804c3c7785f65d53c55f277b6 Mon Sep 17 00:00:00 2001 From: Bram Velthoven <bram.velthoven@finalist.nl> Date: Mon, 7 Apr 2025 15:00:11 +0200 Subject: [PATCH 2/3] Issue #3493640 by bram.velthoven: Update phpstan file and fix eslint prettier issue --- js/conditional_fields.js | 4 ++- phpstan-baseline.neon | 53 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/js/conditional_fields.js b/js/conditional_fields.js index 1a14214..b783615 100644 --- a/js/conditional_fields.js +++ b/js/conditional_fields.js @@ -120,8 +120,10 @@ .on('state:required', (e) => { if (e.trigger) { const fieldsSupportingRequired = $(e.target).find('input, textarea'); + // Option 'N/A' etc should not be present when field is required. - const requiredNoneOption = fieldsSupportingRequired.filter('[id*="component-none"]').parent(); + const requiredNoneOption = fieldsSupportingRequired + .filter('[id*="component-none"]').parent(); const legends = $(e.target).find('legend'); const legendsspan = $(e.target).find('legend span'); const labels = $(e.target).find( diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3818cb4..e4de95c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,17 +1,62 @@ parameters: ignoreErrors: + - + message: "#^Variable \\$parent might not be defined\\.$#" + count: 1 + path: src/ConditionalFieldsElementAlterHelper.php - - message: "#^Variable \\$selectors in empty\\(\\) is never defined\\.$#" + message: "#^Variable \\$error_key_arr on left side of \\?\\? always exists and is not nullable\\.$#" count: 1 - path: src/Plugin/conditional_fields/handler/TextAreaFormatted.php + path: src/ConditionalFieldsFormHelper.php - - message: "#^Undefined variable\\: \\$selectors$#" + message: "#^Variable \\$field_name might not be defined\\.$#" + count: 3 + path: src/ConditionalFieldsFormHelper.php + + - + message: "#^Variable \\$first_field might not be defined\\.$#" count: 1 - path: src/Plugin/conditional_fields/handler/TextAreaFormatted.php + path: src/ConditionalFieldsFormHelper.php + + - + message: "#^Variable \\$storage might not be defined\\.$#" + count: 1 + path: src/ConditionalFieldsFormHelper.php + + - + message: "#^\\\\Drupal calls should be avoided in classes, use dependency injection instead$#" + count: 1 + path: src/ConditionalFieldsFormHelper.php + + - + message: "#^Unsafe usage of new static\\(\\)\\.$#" + count: 1 + path: src/Form/ConditionalFieldDeleteForm.php + + - + message: "#^Unsafe usage of new static\\(\\)\\.$#" + count: 1 + path: src/Form/ConditionalFieldEditForm.php + + - + message: "#^Unsafe usage of new static\\(\\)\\.$#" + count: 1 + path: src/Form/ConditionalFieldForm.php - message: "#^Variable \\$regex in empty\\(\\) is never defined\\.$#" count: 1 path: src/Plugin/conditional_fields/handler/LanguageSelect.php + + - + message: "#^Undefined variable\\: \\$selectors$#" + count: 1 + path: src/Plugin/conditional_fields/handler/TextAreaFormatted.php + + - + message: "#^Variable \\$selectors in empty\\(\\) is never defined\\.$#" + count: 1 + path: src/Plugin/conditional_fields/handler/TextAreaFormatted.php + -- GitLab From 367030cf226ac42e93868711db008e793f9fbec3 Mon Sep 17 00:00:00 2001 From: Bram Velthoven <bram.velthoven@finalist.nl> Date: Mon, 7 Apr 2025 15:18:20 +0200 Subject: [PATCH 3/3] Issue #3493640 by bram.velthoven: Fix eslint --- js/conditional_fields.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/js/conditional_fields.js b/js/conditional_fields.js index b783615..319f7d1 100644 --- a/js/conditional_fields.js +++ b/js/conditional_fields.js @@ -123,7 +123,8 @@ // Option 'N/A' etc should not be present when field is required. const requiredNoneOption = fieldsSupportingRequired - .filter('[id*="component-none"]').parent(); + .filter('[id*="component-none"]') + .parent(); const legends = $(e.target).find('legend'); const legendsspan = $(e.target).find('legend span'); const labels = $(e.target).find( -- GitLab