From 2ee6dbf5b8ee194e0d495d4ea8fc21575151973f 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 df62fc7a02..26b67db957 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 8af3a8fa58..9e628c77ef 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' ignoreTitle: true }; -- 2.25.1