From 1960831298c54a2bfd8df627115520e1e82d0f99 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Sat, 20 Jun 2020 12:04:36 +0100 Subject: [PATCH] Fix issues with select2 validation when it is part of hidden 'On behalf of organisation' block --- .../Form/Contribution/OnBehalfOf.tpl | 19 +++++++++++++++---- templates/CRM/common/l10n.js.tpl | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl index df62fc7a0220..26b67db9573e 100644 --- a/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl +++ b/templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl @@ -54,12 +54,23 @@ selectCreateOrg(orgOption, false); if (is_for_organization.length) { - $('#on-behalf-block').toggle(is_for_organization.is(':checked')); + showHideOnBehalfOfBlock(); + + is_for_organization.on('change', function() { + showHideOnBehalfOfBlock(); + }); } - is_for_organization.on('change', function(){ - $('#on-behalf-block').toggle($(this).is(':checked')); - }); + function showHideOnBehalfOfBlock() { + $('#on-behalf-block').toggle(is_for_organization.is(':checked')); + + if (is_for_organization.is(':checked')) { + $('#onBehalfOfOrg select.crm-select2').removeClass('crm-no-validate'); + } + else { + $('#onBehalfOfOrg select.crm-select2').addClass('crm-no-validate'); + } + } $("input:radio[name='org_option']").click( function( ) { var orgOption = $(this).attr('id'); diff --git a/templates/CRM/common/l10n.js.tpl b/templates/CRM/common/l10n.js.tpl index 023edfa3a64b..bb0c5733c338 100644 --- a/templates/CRM/common/l10n.js.tpl +++ b/templates/CRM/common/l10n.js.tpl @@ -95,7 +95,7 @@ var params = { errorClass: 'crm-inline-error alert-danger', messages: {}, - ignore: ".select2-offscreen, [readonly], :hidden:not(.crm-select2)" + ignore: '.select2-offscreen, [readonly], :hidden:not(.crm-select2), .crm-no-validate' }; // use civicrm notifications when there are errors