Skip to content

Conversation

@jitendrapurohit
Copy link
Contributor

Overview

Fixes #32342 along with original fix included #10826

From #32342:

Steps to replicate:
Create a paid online event registration with price set of radio and checkbox price fields
Add pay later and one or more CC payment processor(s)
Go to event registration form live or on test mode.
Select a radio option and choose pay-later
Select any checkbox price option or change radio price option

Before

The payment processor selection switches to CC from pay-later and billing section is not exposed. I can replicate this issue in dmaster:

After

Fixed

Technical Details

On Hide: We now capture the currently selected payment_processor_id and store it in a data attribute on the billing block.

On Show: check for that data attribute.

If found: restore that specific processor.

If NOT found (and no other processor is currently active), fall back to the default behavior (selecting the processor marked checked=checked).

This preserves the fix for CRM-21038 (ensuring some processor is selected) while respecting explicit user choices during form updates.

Comments

Anything else you would like the reviewer to note

@civibot
Copy link

civibot bot commented Nov 29, 2025

🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷

Introduction for new contributors...
  • If this is your first PR, an admin will greenlight automated testing with the command ok to test or add to whitelist.
  • A series of tests will automatically run. You can see the results at the bottom of this page (if there are any problems, it will include a link to see what went wrong).
  • A demo site will be built where anyone can try out a version of CiviCRM that includes your changes.
  • If this process needs to be repeated, an admin will issue the command test this please to rerun tests and build a new demo site.
  • Before this PR can be merged, it needs to be reviewed. Please keep in mind that reviewers are volunteers, and their response time can vary from a few hours to a few weeks depending on their availability and their knowledge of this particular part of CiviCRM.
  • A great way to speed up this process is to "trade reviews" with someone - find an open PR that you feel able to review, and leave a comment like "I'm reviewing this now, could you please review mine?" (include a link to yours). You don't have to wait for a response to get started (and you don't have to stop at one!) the more you review, the faster this process goes for everyone 😄
  • To ensure that you are credited properly in the final release notes, please add yourself to contributor-key.yml
  • For more information about contributing, see CONTRIBUTING.md.
Quick links for reviewers...

➡️ Online demo of this PR 🔗

else if (cj('input[name="payment_processor_id"]:checked').length === 0) {
cj('input[name="payment_processor_id"][checked=checked]').prop('checked', true);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To further optimize how about :

diff --git a/templates/CRM/common/paymentBlock.tpl b/templates/CRM/common/paymentBlock.tpl
index 8a3c00436b..842880ce41 100644
--- a/templates/CRM/common/paymentBlock.tpl
+++ b/templates/CRM/common/paymentBlock.tpl
@@ -24,7 +24,13 @@
     // might be that the unselecting of the processor should cause it
     // to be hidden (or removed) in which case it can go from this function.
     var billing_block = cj("div#billing-payment-block");
+    let payment_processor_options = cj('input[name="payment_processor_id"]');
     if (isHide) {
+      let checked = payment_processor_options.filter(':checked').val();
+      if (checked) {
+        billing_block.data('saved-ppid', checked);
+      }
+
       payment_options.hide();
       payment_processor.hide();
       payment_information.hide();
@@ -32,7 +38,7 @@
       // Ensure that jquery validation doesn't block submission when we don't need to fill in the billing details section
       cj('#billing-payment-block select.crm-select2').addClass('crm-no-validate');
       // also unset selected payment methods
-      cj('input[name="payment_processor_id"]').removeProp('checked');
+      payment_processor_options.removeProp('checked');
     }
     else {
       payment_options.show();
@@ -41,7 +47,16 @@
       billing_block.show();
       cj('#billing-payment-block select.crm-select2').removeClass('crm-no-validate');
       // also set selected payment methods
-      cj('input[name="payment_processor_id"][checked=checked]').prop('checked', true);
+
+      let saved = billing_block.data('saved-ppid');
+      if (saved && payment_processor_options.filter('[value="' + saved + '"]').length) {
+        payment_processor_options.filter('[value="' + saved + '"]').prop('checked', true);
+        billing_block.removeData('saved-ppid');
+      }
+      else if (!payment_processor_options.is(':checked')) {
+        // Fallback to default
+        payment_processor_options.filter('[checked=checked]').prop('checked', true);
+      }
     }
   }

just removed var declaration with let and use more generic variable to reduce variable declaration like restored_input and current_selection

@monishdeb
Copy link
Member

Thanks for alternate PR. suggested a optimized patch~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants