@4site/engrid-scripts 0.25.2 → 0.25.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,6 +16,7 @@ export interface Options {
16
16
  MinAmountMessage?: string;
17
17
  MaxAmountMessage?: string;
18
18
  UseAmountValidatorFromEN?: boolean;
19
+ DisableLiveValidation?: boolean;
19
20
  SkipToMainContentLink?: boolean;
20
21
  SrcDefer?: boolean;
21
22
  SuppressPurchaseEcard?: boolean;
@@ -6,6 +6,7 @@ export declare class MinMaxAmount {
6
6
  private maxAmount;
7
7
  private minAmountMessage;
8
8
  private maxAmountMessage;
9
+ private disableLiveValidation;
9
10
  private enAmountValidator;
10
11
  private logger;
11
12
  constructor();
@@ -10,6 +10,7 @@ export class MinMaxAmount {
10
10
  this.maxAmount = (_b = ENGrid.getOption("MaxAmount")) !== null && _b !== void 0 ? _b : 100000;
11
11
  this.minAmountMessage = ENGrid.getOption("MinAmountMessage");
12
12
  this.maxAmountMessage = ENGrid.getOption("MaxAmountMessage");
13
+ this.disableLiveValidation = ENGrid.getOption("DisableLiveValidation");
13
14
  this.enAmountValidator = null;
14
15
  this.logger = new EngridLogger("MinMaxAmount", "white", "purple", "🔢");
15
16
  if (!this.shouldRun()) {
@@ -17,8 +18,10 @@ export class MinMaxAmount {
17
18
  return;
18
19
  }
19
20
  this.setValidationConfigFromEN();
20
- this._amount.onAmountChange.subscribe((s) => window.setTimeout(this.liveValidate.bind(this), 1000) // Wait 1 second for the amount to be updated
21
- );
21
+ if (!this.disableLiveValidation) {
22
+ this._amount.onAmountChange.subscribe((s) => window.setTimeout(this.liveValidate.bind(this), 1000) // Wait 1 second for the amount to be updated
23
+ );
24
+ }
22
25
  this._form.onValidate.subscribe(this.enOnValidate.bind(this));
23
26
  }
24
27
  // Should we run the script?
@@ -36,6 +39,14 @@ export class MinMaxAmount {
36
39
  otherAmount.focus();
37
40
  }
38
41
  this._form.validate = false;
42
+ if (this.disableLiveValidation) {
43
+ this.logger.log("Setting error on enOnValidate: " +
44
+ (this.minAmountMessage || "Invalid Amount"));
45
+ // Defer so EN's own onValidate pass can't overwrite the error
46
+ window.setTimeout(() => {
47
+ ENGrid.setError(".en__field--withOther", this.minAmountMessage || "Invalid Amount");
48
+ }, 300);
49
+ }
39
50
  }
40
51
  else if (this._amount.amount > this.maxAmount) {
41
52
  this.logger.log("Amount is greater than max amount: " + this.maxAmount);
@@ -43,11 +54,29 @@ export class MinMaxAmount {
43
54
  otherAmount.focus();
44
55
  }
45
56
  this._form.validate = false;
57
+ if (this.disableLiveValidation) {
58
+ this.logger.log("Setting error on enOnValidate: " +
59
+ (this.maxAmountMessage || "Invalid Amount"));
60
+ // Defer so EN's own onValidate pass can't overwrite the error
61
+ window.setTimeout(() => {
62
+ ENGrid.setError(".en__field--withOther", this.maxAmountMessage || "Invalid Amount");
63
+ }, 300);
64
+ }
65
+ }
66
+ else if (this.disableLiveValidation) {
67
+ // Amount is in range — clear any stale error left over from a previous submit
68
+ ENGrid.removeError(".en__field--withOther");
69
+ }
70
+ if (!this.disableLiveValidation) {
71
+ window.setTimeout(this.liveValidate.bind(this), 300);
46
72
  }
47
- window.setTimeout(this.liveValidate.bind(this), 300);
48
73
  }
49
74
  // Disable Submit Button if the amount is not valid
50
75
  liveValidate() {
76
+ if (this.disableLiveValidation) {
77
+ this.logger.log("disableLiveValidation is set to true. Skipping live validation");
78
+ return;
79
+ }
51
80
  const amount = ENGrid.cleanAmount(this._amount.amount.toString());
52
81
  const activeElement = document.activeElement;
53
82
  if (activeElement &&
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const AppVersion = "0.25.2";
1
+ export declare const AppVersion = "0.25.5";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const AppVersion = "0.25.2";
1
+ export const AppVersion = "0.25.5";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4site/engrid-scripts",
3
- "version": "0.25.2",
3
+ "version": "0.25.5",
4
4
  "description": "Scripts for the ENGRID Project",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -25,7 +25,7 @@
25
25
  "strongly-typed-events": "^2.0.9"
26
26
  },
27
27
  "homepage": "https://github.com/4site-interactive-studios/engrid#readme",
28
- "gitHead": "9ca2921968167be0cea2cfdbb35a85109e9d46bc",
28
+ "gitHead": "f4a3b2759036e89ed5e19c907df1f2224d44f4bb",
29
29
  "devDependencies": {
30
30
  "nodemon": "^2.0.20"
31
31
  }