Skip to content

Commit 84615d3

Browse files
committed
PreferredPaymentMethod: Fix Label Click that was causing Chrome to scroll down the page
1 parent 78e80f4 commit 84615d3

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

packages/scripts/dist/preferred-payment-method.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,23 @@ export class PreferredPaymentMethod {
2626
this.logger.log("Not a donation page. Skipping preferred payment selection.");
2727
return false;
2828
}
29+
// If there's a "payment" URL parameter, we can proceed
30+
if (ENGrid.getUrlParameter("payment")) {
31+
return true;
32+
}
2933
if (!this.getGiveBySelectInputs().length) {
3034
this.logger.log("No give-by-select inputs found. Skipping.");
3135
return false;
3236
}
33-
const config = ENGrid.getOption("PreferredPaymentMethod");
37+
const config = ENGrid.getOption("PreferredPaymentMethod") || false;
3438
if (config === false) {
3539
this.logger.log("PreferredPaymentMethod option disabled.");
3640
return false;
3741
}
3842
return true;
3943
}
4044
resolveConfig() {
41-
const option = ENGrid.getOption("PreferredPaymentMethod");
45+
const option = ENGrid.getOption("PreferredPaymentMethod") || false;
4246
if (option && typeof option === "object") {
4347
const preferredPaymentMethodField = option.preferredPaymentMethodField || "";
4448
const defaultPaymentMethod = Array.isArray(option.defaultPaymentMethod)
@@ -212,14 +216,8 @@ export class PreferredPaymentMethod {
212216
this.logger.log(`Payment method "${method}" is not available to select.`);
213217
return;
214218
}
215-
const label = this.findLabelForInput(input);
216-
if (label) {
217-
label.click();
218-
}
219-
else {
220-
input.checked = true;
221-
input.dispatchEvent(new Event("change", { bubbles: true, cancelable: true }));
222-
}
219+
input.checked = true;
220+
input.dispatchEvent(new Event("change", { bubbles: true, cancelable: true }));
223221
ENGrid.setPaymentType(method);
224222
this.syncPreferredField(input.value);
225223
this.selectionFinalized = true;

packages/scripts/src/preferred-payment-method.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,17 @@ export class PreferredPaymentMethod {
4949
return false;
5050
}
5151

52+
// If there's a "payment" URL parameter, we can proceed
53+
if (ENGrid.getUrlParameter("payment")) {
54+
return true;
55+
}
56+
5257
if (!this.getGiveBySelectInputs().length) {
5358
this.logger.log("No give-by-select inputs found. Skipping.");
5459
return false;
5560
}
5661

57-
const config = ENGrid.getOption("PreferredPaymentMethod");
62+
const config = ENGrid.getOption("PreferredPaymentMethod") || false;
5863
if (config === false) {
5964
this.logger.log("PreferredPaymentMethod option disabled.");
6065
return false;
@@ -64,7 +69,7 @@ export class PreferredPaymentMethod {
6469
}
6570

6671
private resolveConfig(): PreferredPaymentMethodConfig {
67-
const option = ENGrid.getOption("PreferredPaymentMethod");
72+
const option = ENGrid.getOption("PreferredPaymentMethod") || false;
6873
if (option && typeof option === "object") {
6974
const preferredPaymentMethodField =
7075
option.preferredPaymentMethodField || "";
@@ -285,15 +290,10 @@ export class PreferredPaymentMethod {
285290
return;
286291
}
287292

288-
const label = this.findLabelForInput(input);
289-
if (label) {
290-
label.click();
291-
} else {
292-
input.checked = true;
293-
input.dispatchEvent(
294-
new Event("change", { bubbles: true, cancelable: true })
295-
);
296-
}
293+
input.checked = true;
294+
input.dispatchEvent(
295+
new Event("change", { bubbles: true, cancelable: true })
296+
);
297297

298298
ENGrid.setPaymentType(method);
299299
this.syncPreferredField(input.value);

0 commit comments

Comments
 (0)