@aemforms/af-core 0.22.164 → 0.22.165

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.
@@ -57,7 +57,7 @@ const defaultConstraintTypeMessages = Object.freeze({
57
57
  [ConstraintType.RANGE_UNDERFLOW]: 'Value must be greater than or equal to ${0}.',
58
58
  [ConstraintType.TYPE_MISMATCH]: 'Please enter a valid value.',
59
59
  [ConstraintType.VALUE_MISSING]: 'Please fill in this field.',
60
- [ConstraintType.STEP_MISMATCH]: 'Please enter a valid value.',
60
+ [ConstraintType.STEP_MISMATCH]: 'Please enter a valid value. The two nearest valid values are ${0} and ${1}.',
61
61
  [ConstraintType.FORMAT_MISMATCH]: 'Specify the value in allowed format : ${0}.',
62
62
  [ConstraintType.ACCEPT_MISMATCH]: 'The specified file type not supported.',
63
63
  [ConstraintType.FILE_SIZE_MISMATCH]: 'File too large. Reduce size and try again.',
@@ -2543,6 +2543,9 @@ class Container extends Scriptable {
2543
2543
  x.reset();
2544
2544
  });
2545
2545
  }
2546
+ get valid() {
2547
+ return this.items.every((item) => item.valid);
2548
+ }
2546
2549
  validate() {
2547
2550
  return this.items.flatMap(x => {
2548
2551
  return x.validate();
@@ -2679,6 +2682,9 @@ __decorate([
2679
2682
  __decorate([
2680
2683
  dependencyTracked()
2681
2684
  ], Container.prototype, "minItems", null);
2685
+ __decorate([
2686
+ dependencyTracked()
2687
+ ], Container.prototype, "valid", null);
2682
2688
  __decorate([
2683
2689
  dependencyTracked()
2684
2690
  ], Container.prototype, "activeChild", null);
@@ -4967,10 +4973,32 @@ class Field extends Scriptable {
4967
4973
  const afConstraintKey = constraint;
4968
4974
  const html5ConstraintType = constraintKeys[afConstraintKey];
4969
4975
  const constraintTypeMessages = getConstraintTypeMessages();
4970
- return this._jsonModel.constraintMessages?.[afConstraintKey === 'exclusiveMaximum' ? 'maximum' :
4976
+ const customMessage = this._jsonModel.constraintMessages?.[afConstraintKey === 'exclusiveMaximum' ? 'maximum' :
4971
4977
  afConstraintKey === 'exclusiveMinimum' ? 'minimum' :
4972
- afConstraintKey]
4973
- || replaceTemplatePlaceholders(constraintTypeMessages[html5ConstraintType], [this._jsonModel[afConstraintKey]]);
4978
+ afConstraintKey];
4979
+ if (customMessage) {
4980
+ const stepValues = constraint === 'step' ? this._getStepMessageValues() : [this._jsonModel[afConstraintKey]];
4981
+ return replaceTemplatePlaceholders(customMessage, stepValues.length === 2 ? stepValues : [this._jsonModel.step]);
4982
+ }
4983
+ if (constraint === 'step') {
4984
+ const stepValues = this._getStepMessageValues();
4985
+ if (stepValues.length === 2) {
4986
+ return replaceTemplatePlaceholders(constraintTypeMessages[html5ConstraintType], stepValues);
4987
+ }
4988
+ return 'Please enter a valid value.';
4989
+ }
4990
+ return replaceTemplatePlaceholders(constraintTypeMessages[html5ConstraintType], [this._jsonModel[afConstraintKey]]);
4991
+ }
4992
+ _getStepMessageValues() {
4993
+ const result = this.checkStep();
4994
+ if (!result.valid
4995
+ && result.prev != null
4996
+ && result.next != null
4997
+ && Number.isFinite(result.prev)
4998
+ && Number.isFinite(result.next)) {
4999
+ return [result.prev, result.next];
5000
+ }
5001
+ return [];
4974
5002
  }
4975
5003
  get errorMessage() {
4976
5004
  return this._jsonModel.errorMessage;
@@ -5030,7 +5058,7 @@ class Field extends Scriptable {
5030
5058
  let next, prev;
5031
5059
  if (!valid) {
5032
5060
  next = (Math.ceil(qt) * fStep + fIVal) / factor;
5033
- prev = (next - fStep) / factor;
5061
+ prev = next - step;
5034
5062
  }
5035
5063
  return {
5036
5064
  valid,
@@ -5181,7 +5209,7 @@ class Field extends Scriptable {
5181
5209
  else {
5182
5210
  valid = this.checkEnum(value, Constraints);
5183
5211
  constraint = 'enum';
5184
- if (valid && this.type === 'number') {
5212
+ if (valid && (this.type === 'number' || this.type === 'integer')) {
5185
5213
  valid = this.checkStep().valid;
5186
5214
  constraint = 'step';
5187
5215
  }
@@ -179,6 +179,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
179
179
  removeItem(action: Action): void;
180
180
  queueEvent(action: Action): void;
181
181
  reset(): void;
182
+ get valid(): boolean;
182
183
  validate(): import("./types/Model").ValidationError[];
183
184
  dispatch(action: Action): void;
184
185
  importData(dataModel: any): void;
@@ -65,6 +65,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
65
65
  valueOf(): any;
66
66
  toString(): any;
67
67
  getErrorMessage(constraint: keyof (ConstraintsMessages)): string;
68
+ private _getStepMessageValues;
68
69
  get errorMessage(): string | undefined;
69
70
  set errorMessage(e: string | undefined);
70
71
  set constraintMessage(constraint: {
@@ -179,7 +179,7 @@ export declare const getConstraintTypeMessages: () => {
179
179
  rangeUnderflow: "Value must be greater than or equal to ${0}.";
180
180
  typeMismatch: "Please enter a valid value.";
181
181
  valueMissing: "Please fill in this field.";
182
- stepMismatch: "Please enter a valid value.";
182
+ stepMismatch: "Please enter a valid value. The two nearest valid values are ${0} and ${1}.";
183
183
  formatMismatch: "Specify the value in allowed format : ${0}.";
184
184
  acceptMismatch: "The specified file type not supported.";
185
185
  fileSizeMismatch: "File too large. Reduce size and try again.";
@@ -179,6 +179,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
179
179
  removeItem(action: Action): void;
180
180
  queueEvent(action: Action): void;
181
181
  reset(): void;
182
+ get valid(): boolean;
182
183
  validate(): import("./types/Model").ValidationError[];
183
184
  dispatch(action: Action): void;
184
185
  importData(dataModel: any): void;
package/lib/Container.js CHANGED
@@ -347,6 +347,9 @@ class Container extends Scriptable_1.default {
347
347
  x.reset();
348
348
  });
349
349
  }
350
+ get valid() {
351
+ return this.items.every((item) => item.valid);
352
+ }
350
353
  validate() {
351
354
  return this.items.flatMap(x => {
352
355
  return x.validate();
@@ -487,6 +490,9 @@ __decorate([
487
490
  __decorate([
488
491
  (0, BaseNode_1.dependencyTracked)()
489
492
  ], Container.prototype, "minItems", null);
493
+ __decorate([
494
+ (0, BaseNode_1.dependencyTracked)()
495
+ ], Container.prototype, "valid", null);
490
496
  __decorate([
491
497
  (0, BaseNode_1.dependencyTracked)()
492
498
  ], Container.prototype, "activeChild", null);
package/lib/Field.d.ts CHANGED
@@ -65,6 +65,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
65
65
  valueOf(): any;
66
66
  toString(): any;
67
67
  getErrorMessage(constraint: keyof (ConstraintsMessages)): string;
68
+ private _getStepMessageValues;
68
69
  get errorMessage(): string | undefined;
69
70
  set errorMessage(e: string | undefined);
70
71
  set constraintMessage(constraint: {
package/lib/Field.js CHANGED
@@ -478,10 +478,32 @@ class Field extends Scriptable_1.default {
478
478
  const afConstraintKey = constraint;
479
479
  const html5ConstraintType = types_1.constraintKeys[afConstraintKey];
480
480
  const constraintTypeMessages = (0, types_1.getConstraintTypeMessages)();
481
- return ((_a = this._jsonModel.constraintMessages) === null || _a === void 0 ? void 0 : _a[afConstraintKey === 'exclusiveMaximum' ? 'maximum' :
481
+ const customMessage = (_a = this._jsonModel.constraintMessages) === null || _a === void 0 ? void 0 : _a[afConstraintKey === 'exclusiveMaximum' ? 'maximum' :
482
482
  afConstraintKey === 'exclusiveMinimum' ? 'minimum' :
483
- afConstraintKey])
484
- || (0, FormUtils_1.replaceTemplatePlaceholders)(constraintTypeMessages[html5ConstraintType], [this._jsonModel[afConstraintKey]]);
483
+ afConstraintKey];
484
+ if (customMessage) {
485
+ const stepValues = constraint === 'step' ? this._getStepMessageValues() : [this._jsonModel[afConstraintKey]];
486
+ return (0, FormUtils_1.replaceTemplatePlaceholders)(customMessage, stepValues.length === 2 ? stepValues : [this._jsonModel.step]);
487
+ }
488
+ if (constraint === 'step') {
489
+ const stepValues = this._getStepMessageValues();
490
+ if (stepValues.length === 2) {
491
+ return (0, FormUtils_1.replaceTemplatePlaceholders)(constraintTypeMessages[html5ConstraintType], stepValues);
492
+ }
493
+ return 'Please enter a valid value.';
494
+ }
495
+ return (0, FormUtils_1.replaceTemplatePlaceholders)(constraintTypeMessages[html5ConstraintType], [this._jsonModel[afConstraintKey]]);
496
+ }
497
+ _getStepMessageValues() {
498
+ const result = this.checkStep();
499
+ if (!result.valid
500
+ && result.prev != null
501
+ && result.next != null
502
+ && Number.isFinite(result.prev)
503
+ && Number.isFinite(result.next)) {
504
+ return [result.prev, result.next];
505
+ }
506
+ return [];
485
507
  }
486
508
  get errorMessage() {
487
509
  return this._jsonModel.errorMessage;
@@ -537,7 +559,7 @@ class Field extends Scriptable_1.default {
537
559
  let next, prev;
538
560
  if (!valid) {
539
561
  next = (Math.ceil(qt) * fStep + fIVal) / factor;
540
- prev = (next - fStep) / factor;
562
+ prev = next - step;
541
563
  }
542
564
  return {
543
565
  valid,
@@ -688,7 +710,7 @@ class Field extends Scriptable_1.default {
688
710
  else {
689
711
  valid = this.checkEnum(value, Constraints);
690
712
  constraint = 'enum';
691
- if (valid && this.type === 'number') {
713
+ if (valid && (this.type === 'number' || this.type === 'integer')) {
692
714
  valid = this.checkStep().valid;
693
715
  constraint = 'step';
694
716
  }
@@ -179,7 +179,7 @@ export declare const getConstraintTypeMessages: () => {
179
179
  rangeUnderflow: "Value must be greater than or equal to ${0}.";
180
180
  typeMismatch: "Please enter a valid value.";
181
181
  valueMissing: "Please fill in this field.";
182
- stepMismatch: "Please enter a valid value.";
182
+ stepMismatch: "Please enter a valid value. The two nearest valid values are ${0} and ${1}.";
183
183
  formatMismatch: "Specify the value in allowed format : ${0}.";
184
184
  acceptMismatch: "The specified file type not supported.";
185
185
  fileSizeMismatch: "File too large. Reduce size and try again.";
package/lib/types/Json.js CHANGED
@@ -56,7 +56,7 @@ const defaultConstraintTypeMessages = Object.freeze({
56
56
  [exports.ConstraintType.RANGE_UNDERFLOW]: 'Value must be greater than or equal to ${0}.',
57
57
  [exports.ConstraintType.TYPE_MISMATCH]: 'Please enter a valid value.',
58
58
  [exports.ConstraintType.VALUE_MISSING]: 'Please fill in this field.',
59
- [exports.ConstraintType.STEP_MISMATCH]: 'Please enter a valid value.',
59
+ [exports.ConstraintType.STEP_MISMATCH]: 'Please enter a valid value. The two nearest valid values are ${0} and ${1}.',
60
60
  [exports.ConstraintType.FORMAT_MISMATCH]: 'Specify the value in allowed format : ${0}.',
61
61
  [exports.ConstraintType.ACCEPT_MISMATCH]: 'The specified file type not supported.',
62
62
  [exports.ConstraintType.FILE_SIZE_MISMATCH]: 'File too large. Reduce size and try again.',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.164",
3
+ "version": "0.22.165",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "@adobe/json-formula": "0.1.50",
40
- "@aemforms/af-formatters": "^0.22.164"
40
+ "@aemforms/af-formatters": "^0.22.165"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",