@aemforms/af-core 0.22.43 → 0.22.45

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.
@@ -22,6 +22,7 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
22
22
  private _activeChild;
23
23
  private isSiteContainer;
24
24
  private isAFormField;
25
+ private _getFormAndSitesState;
25
26
  private getItemsState;
26
27
  getState(isRepeatableChild?: boolean): T & {
27
28
  items: any[];
package/lib/Container.js CHANGED
@@ -66,24 +66,33 @@ class Container extends Scriptable_1.default {
66
66
  isAFormField(item) {
67
67
  return ('fieldType' in item || 'id' in item || 'name' in item || 'dataRef' in item || 'type' in item);
68
68
  }
69
+ _getFormAndSitesState(isRepeatableChild = false) {
70
+ return this._jsonModel.items ? this._jsonModel.items.map((x) => {
71
+ if (this.isSiteContainer(x)) {
72
+ const newObjWithId = Object.assign({}, ((x === null || x === void 0 ? void 0 : x.id) ? { id: this.form.getUniqueId() } : {}));
73
+ return Object.assign(Object.assign(Object.assign({}, x), newObjWithId), { ':items': this.walkSiteContainerItems(x) });
74
+ }
75
+ else if (this.isAFormField(x)) {
76
+ return Object.assign({}, this.form.getElement(x === null || x === void 0 ? void 0 : x.id).getState(isRepeatableChild));
77
+ }
78
+ else {
79
+ return x;
80
+ }
81
+ }) : [];
82
+ }
69
83
  getItemsState(isRepeatableChild = false) {
70
84
  if (this._jsonModel.type === 'array' || (0, JsonUtils_1.isRepeatable)(this._jsonModel) || isRepeatableChild) {
71
- return this._children.map(x => {
72
- return Object.assign({}, x.getState(true));
73
- });
85
+ if (isRepeatableChild) {
86
+ return this._getFormAndSitesState(isRepeatableChild);
87
+ }
88
+ else {
89
+ return this._children.map(x => {
90
+ return Object.assign({}, x.getState(true));
91
+ });
92
+ }
74
93
  }
75
94
  else {
76
- return this._jsonModel.items ? this._jsonModel.items.map(x => {
77
- if (this.isSiteContainer(x)) {
78
- return Object.assign(Object.assign({}, x), { ':items': this.walkSiteContainerItems(x) });
79
- }
80
- else if (this.isAFormField(x)) {
81
- return Object.assign({}, this.form.getElement(x === null || x === void 0 ? void 0 : x.id).getState(isRepeatableChild));
82
- }
83
- else {
84
- return x;
85
- }
86
- }) : [];
95
+ return this._getFormAndSitesState(isRepeatableChild);
87
96
  }
88
97
  }
89
98
  getState(isRepeatableChild = false) {
@@ -105,7 +114,13 @@ class Container extends Scriptable_1.default {
105
114
  return this.walkSiteContainerItems(value);
106
115
  }
107
116
  else {
108
- return [key, value];
117
+ if (typeof value === 'object') {
118
+ const newObjWithId = Object.assign({}, ((value === null || value === void 0 ? void 0 : value.id) ? { 'id': this.form.getUniqueId() } : {}));
119
+ return [key, Object.assign(Object.assign({}, value), newObjWithId)];
120
+ }
121
+ else {
122
+ return [key, value];
123
+ }
109
124
  }
110
125
  }));
111
126
  }
package/lib/Field.d.ts CHANGED
@@ -32,7 +32,8 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
32
32
  set readOnly(e: boolean | undefined);
33
33
  get enabled(): boolean | undefined;
34
34
  set enabled(e: boolean | undefined);
35
- get valid(): boolean | undefined;
35
+ get valid(): any;
36
+ get validity(): any;
36
37
  get emptyValue(): "" | null | undefined;
37
38
  get enum(): any[] | undefined;
38
39
  set enum(e: any[] | undefined);
@@ -199,6 +200,8 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
199
200
  viewType?: string | undefined;
200
201
  placeholder?: string | undefined;
201
202
  valid?: boolean | undefined;
203
+ validity?: any;
204
+ validationMessage?: string | undefined;
202
205
  default?: any;
203
206
  value?: any;
204
207
  emptyValue?: "" | "undefined" | "null" | undefined;
@@ -207,6 +210,6 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
207
210
  qualifiedName: any;
208
211
  id: string;
209
212
  };
210
- markAsInvalid(message: string): void;
213
+ markAsInvalid(message: string, constraint?: keyof (ConstraintsMessages) | null): void;
211
214
  }
212
215
  export default Field;
package/lib/Field.js CHANGED
@@ -18,6 +18,7 @@ const DataValue_1 = __importDefault(require("./data/DataValue"));
18
18
  const BaseNode_1 = require("./BaseNode");
19
19
  const EmptyDataValue_1 = __importDefault(require("./data/EmptyDataValue"));
20
20
  const af_formatters_1 = require("@aemforms/af-formatters");
21
+ const FormUtils_1 = require("./utils/FormUtils");
21
22
  const validTypes = ['string', 'number', 'integer', 'boolean', 'file', 'string[]', 'number[]', 'integer[]', 'boolean[]', 'file[]', 'array', 'object'];
22
23
  class Field extends Scriptable_1.default {
23
24
  constructor(params, _options) {
@@ -200,7 +201,11 @@ class Field extends Scriptable_1.default {
200
201
  this._setProperty('enabled', e);
201
202
  }
202
203
  get valid() {
203
- return this._jsonModel.valid;
204
+ var _a, _b;
205
+ return (_b = (_a = this._jsonModel) === null || _a === void 0 ? void 0 : _a.validity) === null || _b === void 0 ? void 0 : _b.valid;
206
+ }
207
+ get validity() {
208
+ return this._jsonModel.validity;
204
209
  }
205
210
  get emptyValue() {
206
211
  if (this._jsonModel.emptyValue === 'null') {
@@ -324,21 +329,27 @@ class Field extends Scriptable_1.default {
324
329
  set value(v) {
325
330
  const changes = this.updateDataNodeAndTypedValue(v);
326
331
  let uniqueRes = { valid: true };
332
+ let constraint = 'type';
327
333
  if ((changes === null || changes === void 0 ? void 0 : changes.length) > 0) {
328
334
  let updates = {};
329
335
  const typeRes = ValidationUtils_1.Constraints.type(this.getInternalType() || 'string', v);
330
336
  if (this.parent.uniqueItems && this.parent.type === 'array') {
331
337
  uniqueRes = ValidationUtils_1.Constraints.uniqueItems(this.parent.uniqueItems, this.parent.getDataNode().$value);
338
+ constraint = 'uniqueItems';
332
339
  }
333
340
  if (typeRes.valid && uniqueRes.valid) {
334
341
  updates = this.evaluateConstraints();
335
342
  }
336
343
  else {
337
- const changes = {
338
- 'valid': typeRes.valid && uniqueRes.valid,
339
- 'errorMessage': typeRes.valid && uniqueRes.valid ? '' : this.getErrorMessage('type')
340
- };
341
- updates = this._applyUpdates(['valid', 'errorMessage'], changes);
344
+ const valid = typeRes.valid && uniqueRes.valid;
345
+ const changes = Object.assign({ valid, 'errorMessage': typeRes.valid && uniqueRes.valid ? '' : this.getErrorMessage('type') }, (valid ? {} : {
346
+ 'validationMessage': valid ? '' : this.getErrorMessage(constraint),
347
+ 'validity': {
348
+ valid,
349
+ [types_1.constraintKeys[constraint]]: true
350
+ }
351
+ }));
352
+ updates = this._applyUpdates(['valid', 'errorMessage', 'validationMessage', 'validity'], changes);
342
353
  }
343
354
  if (updates.valid) {
344
355
  this.triggerValidationEvent(updates);
@@ -351,9 +362,13 @@ class Field extends Scriptable_1.default {
351
362
  const changes = this.updateDataNodeAndTypedValue(this.default);
352
363
  const validationStateChanges = {
353
364
  'valid': undefined,
354
- 'errorMessage': ''
365
+ 'errorMessage': '',
366
+ 'validationMessage': '',
367
+ 'validity': {
368
+ valid: undefined
369
+ }
355
370
  };
356
- const updates = this._applyUpdates(['valid', 'errorMessage'], validationStateChanges);
371
+ const updates = this._applyUpdates(['valid', 'errorMessage', 'validationMessage', 'validity'], validationStateChanges);
357
372
  const changeAction = new Events_1.Change({ changes: changes.concat(Object.values(updates)) });
358
373
  this.dispatch(changeAction);
359
374
  }
@@ -392,7 +407,11 @@ class Field extends Scriptable_1.default {
392
407
  }
393
408
  getErrorMessage(constraint) {
394
409
  var _a;
395
- return ((_a = this._jsonModel.constraintMessages) === null || _a === void 0 ? void 0 : _a[constraint]) || '';
410
+ const afConstraintKey = constraint;
411
+ const html5ConstraintType = types_1.constraintKeys[afConstraintKey];
412
+ const constraintTypeMessages = (0, types_1.getConstraintTypeMessages)();
413
+ return ((_a = this._jsonModel.constraintMessages) === null || _a === void 0 ? void 0 : _a[afConstraintKey])
414
+ || (0, FormUtils_1.replaceTemplatePlaceholders)(constraintTypeMessages[html5ConstraintType], [this._jsonModel[afConstraintKey]]);
396
415
  }
397
416
  get errorMessage() {
398
417
  return this._jsonModel.errorMessage;
@@ -595,15 +614,15 @@ class Field extends Scriptable_1.default {
595
614
  if (!valid) {
596
615
  this.form.logger.info(`${constraint} constraint evaluation failed ${this._jsonModel[constraint]}. Received ${this._jsonModel.value}`);
597
616
  }
598
- const changes = {
599
- 'valid': valid,
600
- 'errorMessage': valid ? '' : this.getErrorMessage(constraint)
601
- };
602
- return this._applyUpdates(['valid', 'errorMessage'], changes);
617
+ const changes = Object.assign({ 'valid': valid, 'errorMessage': valid ? '' : this.getErrorMessage(constraint) }, ({
618
+ 'validationMessage': valid ? '' : this.getErrorMessage(constraint),
619
+ 'validity': Object.assign({ valid }, (valid ? {} : { [types_1.constraintKeys[constraint]]: true }))
620
+ }));
621
+ return this._applyUpdates(['valid', 'errorMessage', 'validationMessage', 'validity'], changes);
603
622
  }
604
623
  triggerValidationEvent(changes) {
605
- if (changes.valid) {
606
- if (this.valid) {
624
+ if (changes.validity) {
625
+ if (this.validity.valid) {
607
626
  this.dispatch(new Events_1.Valid());
608
627
  }
609
628
  else {
@@ -616,7 +635,7 @@ class Field extends Scriptable_1.default {
616
635
  return [];
617
636
  }
618
637
  const changes = this.evaluateConstraints();
619
- if (changes.valid) {
638
+ if (changes.validity) {
620
639
  this.triggerValidationEvent(changes);
621
640
  this.notifyDependents(new Events_1.Change({ changes: Object.values(changes) }));
622
641
  }
@@ -638,12 +657,14 @@ class Field extends Scriptable_1.default {
638
657
  getState() {
639
658
  return Object.assign(Object.assign({}, super.getState()), { editFormat: this.editFormat, displayFormat: this.displayFormat, editValue: this.editValue, displayValue: this.displayValue, enabled: this.enabled, readOnly: this.readOnly });
640
659
  }
641
- markAsInvalid(message) {
660
+ markAsInvalid(message, constraint = null) {
642
661
  const changes = {
643
662
  'valid': false,
644
- 'errorMessage': message
663
+ 'errorMessage': message,
664
+ 'validationMessage': message,
665
+ 'validity': Object.assign({ valid: false }, (constraint != null ? { [types_1.constraintKeys[constraint]]: true } : {}))
645
666
  };
646
- const updates = this._applyUpdates(['valid', 'errorMessage'], changes);
667
+ const updates = this._applyUpdates(['valid', 'errorMessage', 'validationMessage', 'validity'], changes);
647
668
  this.triggerValidationEvent(updates);
648
669
  const changeAction = new Events_1.Change({ changes: [].concat(Object.values(updates)) });
649
670
  this.dispatch(changeAction);
@@ -660,6 +681,9 @@ __decorate([
660
681
  __decorate([
661
682
  (0, BaseNode_1.dependencyTracked)()
662
683
  ], Field.prototype, "valid", null);
684
+ __decorate([
685
+ (0, BaseNode_1.dependencyTracked)()
686
+ ], Field.prototype, "validity", null);
663
687
  __decorate([
664
688
  (0, BaseNode_1.dependencyTracked)()
665
689
  ], Field.prototype, "enum", null);
package/lib/Form.js CHANGED
@@ -139,7 +139,9 @@ class Form extends Container_1.default {
139
139
  submit(action, context) {
140
140
  if (this.validate().length === 0) {
141
141
  const payload = (action === null || action === void 0 ? void 0 : action.payload) || {};
142
- (0, FunctionRuntime_1.submit)(context, payload === null || payload === void 0 ? void 0 : payload.success, payload === null || payload === void 0 ? void 0 : payload.error, payload === null || payload === void 0 ? void 0 : payload.submit_as, payload === null || payload === void 0 ? void 0 : payload.data);
142
+ const successEventName = (payload === null || payload === void 0 ? void 0 : payload.success) ? payload === null || payload === void 0 ? void 0 : payload.success : 'submitSuccess';
143
+ const failureEventName = (payload === null || payload === void 0 ? void 0 : payload.error) ? payload === null || payload === void 0 ? void 0 : payload.error : 'submitFailure';
144
+ (0, FunctionRuntime_1.submit)(context, successEventName, failureEventName, payload === null || payload === void 0 ? void 0 : payload.submit_as, payload === null || payload === void 0 ? void 0 : payload.data);
143
145
  }
144
146
  }
145
147
  reset() {
@@ -60,6 +60,12 @@ export declare class Focus extends ActionImpl {
60
60
  export declare class Submit extends ActionImpl {
61
61
  constructor(payload?: any, dispatch?: boolean);
62
62
  }
63
+ export declare class SubmitSuccess extends ActionImpl {
64
+ constructor(payload?: any, dispatch?: boolean);
65
+ }
66
+ export declare class SubmitFailure extends ActionImpl {
67
+ constructor(payload?: any, dispatch?: boolean);
68
+ }
63
69
  export declare class Reset extends ActionImpl {
64
70
  constructor(payload?: any, dispatch?: boolean);
65
71
  }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RemoveInstance = exports.AddInstance = exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Reset = exports.Submit = exports.Focus = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.Change = void 0;
3
+ exports.RemoveInstance = exports.AddInstance = exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Reset = exports.SubmitFailure = exports.SubmitSuccess = exports.Submit = exports.Focus = exports.ValidationComplete = exports.Blur = exports.Click = exports.FormLoad = exports.Initialize = exports.propertyChange = exports.ExecuteRule = exports.Valid = exports.Invalid = exports.Change = void 0;
4
4
  class ActionImpl {
5
5
  constructor(payload, type, _metadata) {
6
6
  this._metadata = _metadata;
@@ -117,6 +117,18 @@ class Submit extends ActionImpl {
117
117
  }
118
118
  }
119
119
  exports.Submit = Submit;
120
+ class SubmitSuccess extends ActionImpl {
121
+ constructor(payload, dispatch = false) {
122
+ super(payload, 'submitSuccess', { dispatch });
123
+ }
124
+ }
125
+ exports.SubmitSuccess = SubmitSuccess;
126
+ class SubmitFailure extends ActionImpl {
127
+ constructor(payload, dispatch = false) {
128
+ super(payload, 'submitFailure', { dispatch });
129
+ }
130
+ }
131
+ exports.SubmitFailure = SubmitFailure;
120
132
  class Reset extends ActionImpl {
121
133
  constructor(payload, dispatch = false) {
122
134
  super(payload, 'reset', { dispatch });
@@ -59,12 +59,22 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
59
59
  const result = yield (0, Fetch_1.request)(endpoint, inputPayload, requestOptions);
60
60
  if ((result === null || result === void 0 ? void 0 : result.status) >= 200 && (result === null || result === void 0 ? void 0 : result.status) <= 299) {
61
61
  const eName = getCustomEventName(success);
62
- context.form.dispatch(new Events_1.CustomEvent(eName, result, true));
62
+ if (eName === 'submitSuccess') {
63
+ context.form.dispatch(new Events_1.SubmitSuccess(result, true));
64
+ }
65
+ else {
66
+ context.form.dispatch(new Events_1.CustomEvent(eName, result, true));
67
+ }
63
68
  }
64
69
  else {
65
70
  context.form.logger.error('Error invoking a rest API');
66
71
  const eName = getCustomEventName(error);
67
- context.form.dispatch(new Events_1.CustomEvent(eName, result, true));
72
+ if (eName === 'submitFailure') {
73
+ context.form.dispatch(new Events_1.SubmitFailure(result, true));
74
+ }
75
+ else {
76
+ context.form.dispatch(new Events_1.CustomEvent(eName, result, true));
77
+ }
68
78
  }
69
79
  });
70
80
  exports.request = request;
@@ -90,6 +90,8 @@ declare type TranslationFieldJson = {
90
90
  export declare type FieldJson = BaseJson & TranslationFieldJson & {
91
91
  readOnly?: boolean;
92
92
  valid?: boolean;
93
+ validity?: any;
94
+ validationMessage?: string;
93
95
  default?: any;
94
96
  value?: any;
95
97
  displayFormat?: string;
@@ -122,4 +124,56 @@ export declare type FormJson = ContainerJson & {
122
124
  export declare type TranslationJson = TranslationBaseJson & TranslationFieldJson & TranslationConstraintsJson;
123
125
  export declare const translationProps: string[];
124
126
  export declare const constraintProps: string[];
127
+ export declare const ConstraintType: Readonly<{
128
+ PATTERN_MISMATCH: "patternMismatch";
129
+ TOO_SHORT: "tooShort";
130
+ TOO_LONG: "tooLong";
131
+ RANGE_OVERFLOW: "rangeOverflow";
132
+ RANGE_UNDERFLOW: "rangeUnderflow";
133
+ TYPE_MISMATCH: "typeMismatch";
134
+ VALUE_MISSING: "valueMissing";
135
+ STEP_MISMATCH: "stepMismatch";
136
+ FORMAT_MISMATCH: "formatMismatch";
137
+ ACCEPT_MISMATCH: "acceptMismatch";
138
+ FILE_SIZE_MISMATCH: "fileSizeMismatch";
139
+ UNIQUE_ITEMS_MISMATCH: "uniqueItemsMismatch";
140
+ MIN_ITEMS_MISMATCH: "minItemsMismatch";
141
+ MAX_ITEMS_MISMATCH: "maxItemsMismatch";
142
+ EXPRESSION_MISMATCH: "expressionMismatch";
143
+ }>;
144
+ export declare const constraintKeys: Readonly<{
145
+ pattern: "patternMismatch";
146
+ minLength: "tooShort";
147
+ maxLength: "tooLong";
148
+ maximum: "rangeOverflow";
149
+ minimum: "rangeUnderflow";
150
+ type: "typeMismatch";
151
+ required: "valueMissing";
152
+ step: "stepMismatch";
153
+ format: "formatMismatch";
154
+ accept: "acceptMismatch";
155
+ maxFileSize: "fileSizeMismatch";
156
+ uniqueItems: "uniqueItemsMismatch";
157
+ minItems: "minItemsMismatch";
158
+ maxItems: "maxItemsMismatch";
159
+ validationExpression: "expressionMismatch";
160
+ }>;
161
+ export declare const setCustomDefaultConstraintTypeMessages: (messages: Record<string, string>) => void;
162
+ export declare const getConstraintTypeMessages: () => {
163
+ patternMismatch: "Please match the format requested.";
164
+ tooShort: "Please lengthen this text to ${0} characters or more.";
165
+ tooLong: "Please shorten this text to ${0} characters or less.";
166
+ rangeOverflow: "Value must be less than or equal to ${0}.";
167
+ rangeUnderflow: "Value must be greater than or equal to ${0}.";
168
+ typeMismatch: "Please enter a valid value.";
169
+ valueMissing: "Please fill in this field.";
170
+ stepMismatch: "Please enter a valid value.";
171
+ formatMismatch: "Specify the value in allowed format : ${0}.";
172
+ acceptMismatch: "The specified file type not supported.";
173
+ fileSizeMismatch: "File too large. Reduce size and try again.";
174
+ uniqueItemsMismatch: "All the items must be unique.";
175
+ minItemsMismatch: "Specify a number of items equal to or greater than ${0}.";
176
+ maxItemsMismatch: "Specify a number of items equal to or less than ${0}.";
177
+ expressionMismatch: "Please enter a valid value.";
178
+ };
125
179
  export {};
package/lib/types/Json.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.constraintProps = exports.translationProps = void 0;
3
+ exports.getConstraintTypeMessages = exports.setCustomDefaultConstraintTypeMessages = exports.constraintKeys = exports.ConstraintType = exports.constraintProps = exports.translationProps = void 0;
4
4
  exports.translationProps = ['description', 'placeholder', 'enum', 'enumNames', 'label.value', 'constraintMessages.accept',
5
5
  'constraintMessages.enum', 'constraintMessages.exclusiveMinimum', 'constraintMessages.exclusiveMaximum', 'constraintMessages.format', 'constraintMessages.maxFileSize', 'constraintMessages.maxLength',
6
6
  'constraintMessages.maximum', 'constraintMessages.maxItems', 'constraintMessages.minLength', 'constraintMessages.minimum', 'constraintMessages.minItems', 'constraintMessages.pattern', 'constraintMessages.required',
@@ -8,3 +8,79 @@ exports.translationProps = ['description', 'placeholder', 'enum', 'enumNames', '
8
8
  exports.constraintProps = ['accept', 'enum', 'exclusiveMinimum', 'exclusiveMaximum',
9
9
  'format', 'maxFileSize', 'maxLength', 'maximum', 'maxItems',
10
10
  'minLength', 'minimum', 'minItems', 'pattern', 'required', 'step', 'validationExpression', 'enumNames'];
11
+ exports.ConstraintType = Object.freeze({
12
+ PATTERN_MISMATCH: 'patternMismatch',
13
+ TOO_SHORT: 'tooShort',
14
+ TOO_LONG: 'tooLong',
15
+ RANGE_OVERFLOW: 'rangeOverflow',
16
+ RANGE_UNDERFLOW: 'rangeUnderflow',
17
+ TYPE_MISMATCH: 'typeMismatch',
18
+ VALUE_MISSING: 'valueMissing',
19
+ STEP_MISMATCH: 'stepMismatch',
20
+ FORMAT_MISMATCH: 'formatMismatch',
21
+ ACCEPT_MISMATCH: 'acceptMismatch',
22
+ FILE_SIZE_MISMATCH: 'fileSizeMismatch',
23
+ UNIQUE_ITEMS_MISMATCH: 'uniqueItemsMismatch',
24
+ MIN_ITEMS_MISMATCH: 'minItemsMismatch',
25
+ MAX_ITEMS_MISMATCH: 'maxItemsMismatch',
26
+ EXPRESSION_MISMATCH: 'expressionMismatch'
27
+ });
28
+ exports.constraintKeys = Object.freeze({
29
+ pattern: exports.ConstraintType.PATTERN_MISMATCH,
30
+ minLength: exports.ConstraintType.TOO_SHORT,
31
+ maxLength: exports.ConstraintType.TOO_LONG,
32
+ maximum: exports.ConstraintType.RANGE_OVERFLOW,
33
+ minimum: exports.ConstraintType.RANGE_UNDERFLOW,
34
+ type: exports.ConstraintType.TYPE_MISMATCH,
35
+ required: exports.ConstraintType.VALUE_MISSING,
36
+ step: exports.ConstraintType.STEP_MISMATCH,
37
+ format: exports.ConstraintType.FORMAT_MISMATCH,
38
+ accept: exports.ConstraintType.ACCEPT_MISMATCH,
39
+ maxFileSize: exports.ConstraintType.FILE_SIZE_MISMATCH,
40
+ uniqueItems: exports.ConstraintType.UNIQUE_ITEMS_MISMATCH,
41
+ minItems: exports.ConstraintType.MIN_ITEMS_MISMATCH,
42
+ maxItems: exports.ConstraintType.MAX_ITEMS_MISMATCH,
43
+ validationExpression: exports.ConstraintType.EXPRESSION_MISMATCH
44
+ });
45
+ const defaultConstraintTypeMessages = Object.freeze({
46
+ [exports.ConstraintType.PATTERN_MISMATCH]: 'Please match the format requested.',
47
+ [exports.ConstraintType.TOO_SHORT]: 'Please lengthen this text to ${0} characters or more.',
48
+ [exports.ConstraintType.TOO_LONG]: 'Please shorten this text to ${0} characters or less.',
49
+ [exports.ConstraintType.RANGE_OVERFLOW]: 'Value must be less than or equal to ${0}.',
50
+ [exports.ConstraintType.RANGE_UNDERFLOW]: 'Value must be greater than or equal to ${0}.',
51
+ [exports.ConstraintType.TYPE_MISMATCH]: 'Please enter a valid value.',
52
+ [exports.ConstraintType.VALUE_MISSING]: 'Please fill in this field.',
53
+ [exports.ConstraintType.STEP_MISMATCH]: 'Please enter a valid value.',
54
+ [exports.ConstraintType.FORMAT_MISMATCH]: 'Specify the value in allowed format : ${0}.',
55
+ [exports.ConstraintType.ACCEPT_MISMATCH]: 'The specified file type not supported.',
56
+ [exports.ConstraintType.FILE_SIZE_MISMATCH]: 'File too large. Reduce size and try again.',
57
+ [exports.ConstraintType.UNIQUE_ITEMS_MISMATCH]: 'All the items must be unique.',
58
+ [exports.ConstraintType.MIN_ITEMS_MISMATCH]: 'Specify a number of items equal to or greater than ${0}.',
59
+ [exports.ConstraintType.MAX_ITEMS_MISMATCH]: 'Specify a number of items equal to or less than ${0}.',
60
+ [exports.ConstraintType.EXPRESSION_MISMATCH]: 'Please enter a valid value.'
61
+ });
62
+ const transformObjectKeys = (obj, transformer) => {
63
+ if (typeof obj !== 'object' || obj === null) {
64
+ return obj;
65
+ }
66
+ if (Array.isArray(obj)) {
67
+ return obj.map((item) => transformObjectKeys(item, transformer));
68
+ }
69
+ return Object.keys(obj).reduce((transformedObj, key) => {
70
+ const transformedKey = transformer(key);
71
+ const value = obj[key];
72
+ transformedObj[transformedKey] = transformObjectKeys(value, transformer);
73
+ return transformedObj;
74
+ }, {});
75
+ };
76
+ let customConstraintTypeMessages = {};
77
+ const setCustomDefaultConstraintTypeMessages = (messages) => {
78
+ customConstraintTypeMessages = transformObjectKeys(messages, (key) => {
79
+ return exports.constraintKeys[key];
80
+ });
81
+ };
82
+ exports.setCustomDefaultConstraintTypeMessages = setCustomDefaultConstraintTypeMessages;
83
+ const getConstraintTypeMessages = () => {
84
+ return Object.assign(Object.assign({}, defaultConstraintTypeMessages), customConstraintTypeMessages);
85
+ };
86
+ exports.getConstraintTypeMessages = getConstraintTypeMessages;
@@ -11,3 +11,4 @@ export declare const dataURItoBlob: (dataURI: string) => {
11
11
  blob: Blob;
12
12
  } | null;
13
13
  export declare const sitesModelToFormModel: (sitesModel: any) => any;
14
+ export declare const replaceTemplatePlaceholders: (str: string, values?: any[]) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.sitesModelToFormModel = exports.dataURItoBlob = exports.extractFileInfo = exports.isDataUrl = exports.IdGenerator = exports.getFileSizeInBytes = exports.getAttachments = exports.isEmpty = exports.randomWord = void 0;
3
+ exports.replaceTemplatePlaceholders = exports.sitesModelToFormModel = exports.dataURItoBlob = exports.extractFileInfo = exports.isDataUrl = exports.IdGenerator = exports.getFileSizeInBytes = exports.getAttachments = exports.isEmpty = exports.randomWord = void 0;
4
4
  const JsonUtils_1 = require("./JsonUtils");
5
5
  const FileObject_1 = require("../FileObject");
6
6
  const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'.split('');
@@ -224,3 +224,10 @@ const sitesModelToFormModel = (sitesModel) => {
224
224
  return sitesModel;
225
225
  };
226
226
  exports.sitesModelToFormModel = sitesModelToFormModel;
227
+ const replaceTemplatePlaceholders = (str, values = []) => {
228
+ return str === null || str === void 0 ? void 0 : str.replace(/\${(\d+)}/g, (match, index) => {
229
+ const replacement = values[index];
230
+ return typeof replacement !== 'undefined' ? replacement : match;
231
+ });
232
+ };
233
+ exports.replaceTemplatePlaceholders = replaceTemplatePlaceholders;
@@ -35,6 +35,11 @@ const addTranslationId = (input, additionalTranslationProps = []) => {
35
35
  exports.addTranslationId = addTranslationId;
36
36
  const _createTranslationId = (input, path, transProps) => {
37
37
  Object.entries(input).forEach(([key, value]) => {
38
+ if (key === 'enumNames' && value instanceof Array) {
39
+ value = value.map((x) => {
40
+ return typeof x === 'string' ? x : x === null || x === void 0 ? void 0 : x.value;
41
+ });
42
+ }
38
43
  if (typeof value == 'object') {
39
44
  if (input instanceof Array) {
40
45
  if (value && 'name' in value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.43",
3
+ "version": "0.22.45",
4
4
  "description": "Core Module for Forms Runtime",
5
5
  "author": "Adobe Systems",
6
6
  "license": "Adobe Proprietary",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "dependencies": {
37
37
  "@adobe/json-formula": "0.1.50",
38
- "@aemforms/af-formatters": "^0.22.43"
38
+ "@aemforms/af-formatters": "^0.22.45"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@babel/preset-env": "^7.20.2",