@aemforms/af-core 0.22.80 → 0.22.82

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.
@@ -2284,9 +2284,14 @@ class FormMetaData extends Node {
2284
2284
  class SubmitMetaData {
2285
2285
  lang;
2286
2286
  captchaInfo;
2287
- constructor(lang = '', captchaInfo) {
2288
- this.lang = lang;
2289
- this.captchaInfo = captchaInfo;
2287
+ constructor(options = {}) {
2288
+ this.lang = options.lang || 'en';
2289
+ this.captchaInfo = options.captchaInfo || {};
2290
+ Object.keys(options).forEach(key => {
2291
+ if (key !== 'lang' && key !== 'captchaInfo') {
2292
+ this[key] = options[key];
2293
+ }
2294
+ });
2290
2295
  }
2291
2296
  }
2292
2297
 
@@ -2650,12 +2655,17 @@ class FunctionRuntimeImpl {
2650
2655
  const eventName = 'reset';
2651
2656
  target = target || 'reset';
2652
2657
  const args = [target, eventName];
2658
+ interpreter.globals.form.logger.warn('This usage of reset is deprecated. Please see the documentation and update.');
2653
2659
  return FunctionRuntimeImpl.getInstance().getFunctions().dispatchEvent._func.call(undefined, args, data, interpreter);
2654
2660
  },
2655
2661
  validate: (target) => {
2656
2662
  const args = [target];
2657
2663
  return FunctionRuntimeImpl.getInstance().getFunctions().validate._func.call(undefined, args, data, interpreter);
2658
2664
  },
2665
+ importData: (inputData) => {
2666
+ const args = [inputData];
2667
+ return FunctionRuntimeImpl.getInstance().getFunctions().importData._func.call(undefined, args, data, interpreter);
2668
+ },
2659
2669
  exportData: () => {
2660
2670
  return FunctionRuntimeImpl.getInstance().getFunctions().exportData._func.call(undefined, args, data, interpreter);
2661
2671
  },
@@ -2678,6 +2688,14 @@ class FunctionRuntimeImpl {
2678
2688
  else if (option && option.useQualifiedName) {
2679
2689
  interpreter.globals.form.resolveQualifiedName(fieldIdentifier)?.markAsInvalid(validationMessage);
2680
2690
  }
2691
+ },
2692
+ setFocus: (target, flag) => {
2693
+ const args = [target, flag];
2694
+ return FunctionRuntimeImpl.getInstance().getFunctions().setFocus._func.call(undefined, args, data, interpreter);
2695
+ },
2696
+ dispatchEvent: (target, eventName, payload) => {
2697
+ const args = [target, eventName, payload];
2698
+ return FunctionRuntimeImpl.getInstance().getFunctions().dispatchEvent._func.call(undefined, args, data, interpreter);
2681
2699
  }
2682
2700
  }
2683
2701
  };
@@ -2734,7 +2752,7 @@ class FunctionRuntimeImpl {
2734
2752
  validation = interpreter.globals.form.getElement(element.$id).validate();
2735
2753
  }
2736
2754
  if (Array.isArray(validation) && validation.length) {
2737
- interpreter.globals.form.logger.error('Form Validation Error');
2755
+ interpreter.globals.form.logger.warn('Form Validation Error');
2738
2756
  }
2739
2757
  return validation;
2740
2758
  },
@@ -2956,6 +2974,7 @@ const changeEventVersion = new Version('0.13');
2956
2974
  class Form extends Container {
2957
2975
  _ruleEngine;
2958
2976
  _eventQueue;
2977
+ additionalSubmitMetadata = {};
2959
2978
  _fields = {};
2960
2979
  _ids;
2961
2980
  _invalidFields = [];
@@ -3012,6 +3031,9 @@ class Form extends Container {
3012
3031
  exportData() {
3013
3032
  return this.getDataNode()?.$value;
3014
3033
  }
3034
+ setAdditionalSubmitMetadata(metadata) {
3035
+ this.additionalSubmitMetadata = { ...this.additionalSubmitMetadata, ...metadata };
3036
+ }
3015
3037
  get specVersion() {
3016
3038
  if (typeof this._jsonModel.adaptiveform === 'string') {
3017
3039
  try {
@@ -3037,21 +3059,18 @@ class Form extends Container {
3037
3059
  return foundFormElement;
3038
3060
  }
3039
3061
  exportSubmitMetaData() {
3040
- let submitMetaInstance = null;
3041
3062
  const captchaInfoObj = {};
3042
- function addCaptchaField(fieldName, fieldValue) {
3043
- if (captchaInfoObj[fieldName]) {
3044
- return;
3045
- }
3046
- captchaInfoObj[fieldName] = fieldValue;
3047
- }
3048
3063
  this.visit(field => {
3049
3064
  if (field.fieldType === 'captcha') {
3050
- addCaptchaField(field.qualifiedName, field.value);
3065
+ captchaInfoObj[field.qualifiedName] = field.value;
3051
3066
  }
3052
3067
  });
3053
- submitMetaInstance = new SubmitMetaData(this.form.lang, captchaInfoObj);
3054
- return submitMetaInstance;
3068
+ const options = {
3069
+ lang: this.lang,
3070
+ captchaInfo: captchaInfoObj,
3071
+ additionalSubmitMetadata: { ...this.additionalSubmitMetadata }
3072
+ };
3073
+ return new SubmitMetaData(options);
3055
3074
  }
3056
3075
  #getNavigableChildren(children) {
3057
3076
  return children.filter(child => child.visible === true);
@@ -3618,7 +3637,8 @@ class Field extends Scriptable {
3618
3637
  }
3619
3638
  set valid(e) {
3620
3639
  const validity = {
3621
- valid: e
3640
+ valid: e,
3641
+ ...(e ? {} : { customConstraint: true })
3622
3642
  };
3623
3643
  this._setProperty('valid', e);
3624
3644
  this._setProperty('validity', validity);
@@ -3786,6 +3806,9 @@ class Field extends Scriptable {
3786
3806
  }
3787
3807
  reset() {
3788
3808
  const changes = this.updateDataNodeAndTypedValue(this.default);
3809
+ if (!changes) {
3810
+ return;
3811
+ }
3789
3812
  const validationStateChanges = {
3790
3813
  'valid': undefined,
3791
3814
  'errorMessage': '',
@@ -4109,7 +4132,7 @@ class Field extends Scriptable {
4109
4132
  'validationMessage': message,
4110
4133
  'validity': {
4111
4134
  valid: false,
4112
- ...(constraint != null ? { [constraintKeys[constraint]]: true } : {})
4135
+ ...(constraint != null ? { [constraintKeys[constraint]]: true } : { customConstraint: true })
4113
4136
  }
4114
4137
  };
4115
4138
  const updates = this._applyUpdates(['valid', 'errorMessage', 'validationMessage', 'validity'], changes);
@@ -11,6 +11,7 @@ declare class Form extends Container<FormJson> implements FormModel {
11
11
  #private;
12
12
  private _ruleEngine;
13
13
  private _eventQueue;
14
+ private additionalSubmitMetadata;
14
15
  private _fields;
15
16
  _ids: Generator<string, void, string>;
16
17
  private _invalidFields;
@@ -24,6 +25,7 @@ declare class Form extends Container<FormJson> implements FormModel {
24
25
  get action(): string | undefined;
25
26
  importData(dataModel: any): void;
26
27
  exportData(): any;
28
+ setAdditionalSubmitMetadata(metadata: Record<string, any>): void;
27
29
  get specVersion(): Version;
28
30
  resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
29
31
  exportSubmitMetaData(): SubmitMetaData;
@@ -1,7 +1,8 @@
1
1
  import { SubmitMetaDataModel } from './types/index';
2
2
  declare class SubmitMetaData implements SubmitMetaDataModel {
3
3
  lang: string;
4
- captchaInfo: Record<string, any>;
5
- constructor(lang: string | undefined, captchaInfo: Record<string, any>);
4
+ captchaInfo: Record<string, string>;
5
+ [key: string]: any;
6
+ constructor(options?: Record<string, any>);
6
7
  }
7
8
  export default SubmitMetaData;
package/lib/Field.js CHANGED
@@ -222,9 +222,7 @@ class Field extends Scriptable_1.default {
222
222
  return (_b = (_a = this._jsonModel) === null || _a === void 0 ? void 0 : _a.validity) === null || _b === void 0 ? void 0 : _b.valid;
223
223
  }
224
224
  set valid(e) {
225
- const validity = {
226
- valid: e
227
- };
225
+ const validity = Object.assign({ valid: e }, (e ? {} : { customConstraint: true }));
228
226
  this._setProperty('valid', e);
229
227
  this._setProperty('validity', validity);
230
228
  }
@@ -387,6 +385,9 @@ class Field extends Scriptable_1.default {
387
385
  }
388
386
  reset() {
389
387
  const changes = this.updateDataNodeAndTypedValue(this.default);
388
+ if (!changes) {
389
+ return;
390
+ }
390
391
  const validationStateChanges = {
391
392
  'valid': undefined,
392
393
  'errorMessage': '',
@@ -689,7 +690,7 @@ class Field extends Scriptable_1.default {
689
690
  'valid': false,
690
691
  'errorMessage': message,
691
692
  'validationMessage': message,
692
- 'validity': Object.assign({ valid: false }, (constraint != null ? { [types_1.constraintKeys[constraint]]: true } : {}))
693
+ 'validity': Object.assign({ valid: false }, (constraint != null ? { [types_1.constraintKeys[constraint]]: true } : { customConstraint: true }))
693
694
  };
694
695
  const updates = this._applyUpdates(['valid', 'errorMessage', 'validationMessage', 'validity'], changes);
695
696
  const changeAction = new Events_1.Change({ changes: [].concat(Object.values(updates)) });
package/lib/Form.d.ts CHANGED
@@ -11,6 +11,7 @@ declare class Form extends Container<FormJson> implements FormModel {
11
11
  #private;
12
12
  private _ruleEngine;
13
13
  private _eventQueue;
14
+ private additionalSubmitMetadata;
14
15
  private _fields;
15
16
  _ids: Generator<string, void, string>;
16
17
  private _invalidFields;
@@ -24,6 +25,7 @@ declare class Form extends Container<FormJson> implements FormModel {
24
25
  get action(): string | undefined;
25
26
  importData(dataModel: any): void;
26
27
  exportData(): any;
28
+ setAdditionalSubmitMetadata(metadata: Record<string, any>): void;
27
29
  get specVersion(): Version;
28
30
  resolveQualifiedName(qualifiedName: string): FieldModel | FieldsetModel | null;
29
31
  exportSubmitMetaData(): SubmitMetaData;
package/lib/Form.js CHANGED
@@ -29,6 +29,7 @@ class Form extends Container_1.default {
29
29
  this._ruleEngine = _ruleEngine;
30
30
  this._eventQueue = _eventQueue;
31
31
  _Form_instances.add(this);
32
+ this.additionalSubmitMetadata = {};
32
33
  this._fields = {};
33
34
  this._invalidFields = [];
34
35
  this.dataRefRegex = /("[^"]+?"|[^.]+?)(?:\.|$)/g;
@@ -80,6 +81,9 @@ class Form extends Container_1.default {
80
81
  var _a;
81
82
  return (_a = this.getDataNode()) === null || _a === void 0 ? void 0 : _a.$value;
82
83
  }
84
+ setAdditionalSubmitMetadata(metadata) {
85
+ this.additionalSubmitMetadata = Object.assign(Object.assign({}, this.additionalSubmitMetadata), metadata);
86
+ }
83
87
  get specVersion() {
84
88
  if (typeof this._jsonModel.adaptiveform === 'string') {
85
89
  try {
@@ -105,21 +109,18 @@ class Form extends Container_1.default {
105
109
  return foundFormElement;
106
110
  }
107
111
  exportSubmitMetaData() {
108
- let submitMetaInstance = null;
109
112
  const captchaInfoObj = {};
110
- function addCaptchaField(fieldName, fieldValue) {
111
- if (captchaInfoObj[fieldName]) {
112
- return;
113
- }
114
- captchaInfoObj[fieldName] = fieldValue;
115
- }
116
113
  this.visit(field => {
117
114
  if (field.fieldType === 'captcha') {
118
- addCaptchaField(field.qualifiedName, field.value);
115
+ captchaInfoObj[field.qualifiedName] = field.value;
119
116
  }
120
117
  });
121
- submitMetaInstance = new SubmitMetaData_1.default(this.form.lang, captchaInfoObj);
122
- return submitMetaInstance;
118
+ const options = {
119
+ lang: this.lang,
120
+ captchaInfo: captchaInfoObj,
121
+ additionalSubmitMetadata: Object.assign({}, this.additionalSubmitMetadata)
122
+ };
123
+ return new SubmitMetaData_1.default(options);
123
124
  }
124
125
  setFocus(field, focusOption) {
125
126
  if (!focusOption) {
@@ -1,7 +1,8 @@
1
1
  import { SubmitMetaDataModel } from './types/index';
2
2
  declare class SubmitMetaData implements SubmitMetaDataModel {
3
3
  lang: string;
4
- captchaInfo: Record<string, any>;
5
- constructor(lang: string | undefined, captchaInfo: Record<string, any>);
4
+ captchaInfo: Record<string, string>;
5
+ [key: string]: any;
6
+ constructor(options?: Record<string, any>);
6
7
  }
7
8
  export default SubmitMetaData;
@@ -1,9 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  class SubmitMetaData {
4
- constructor(lang = '', captchaInfo) {
5
- this.lang = lang;
6
- this.captchaInfo = captchaInfo;
4
+ constructor(options = {}) {
5
+ this.lang = options.lang || 'en';
6
+ this.captchaInfo = options.captchaInfo || {};
7
+ Object.keys(options).forEach(key => {
8
+ if (key !== 'lang' && key !== 'captchaInfo') {
9
+ this[key] = options[key];
10
+ }
11
+ });
7
12
  }
8
13
  }
9
14
  exports.default = SubmitMetaData;
@@ -196,12 +196,17 @@ class FunctionRuntimeImpl {
196
196
  const eventName = 'reset';
197
197
  target = target || 'reset';
198
198
  const args = [target, eventName];
199
+ interpreter.globals.form.logger.warn('This usage of reset is deprecated. Please see the documentation and update.');
199
200
  return FunctionRuntimeImpl.getInstance().getFunctions().dispatchEvent._func.call(undefined, args, data, interpreter);
200
201
  },
201
202
  validate: (target) => {
202
203
  const args = [target];
203
204
  return FunctionRuntimeImpl.getInstance().getFunctions().validate._func.call(undefined, args, data, interpreter);
204
205
  },
206
+ importData: (inputData) => {
207
+ const args = [inputData];
208
+ return FunctionRuntimeImpl.getInstance().getFunctions().importData._func.call(undefined, args, data, interpreter);
209
+ },
205
210
  exportData: () => {
206
211
  return FunctionRuntimeImpl.getInstance().getFunctions().exportData._func.call(undefined, args, data, interpreter);
207
212
  },
@@ -225,6 +230,14 @@ class FunctionRuntimeImpl {
225
230
  else if (option && option.useQualifiedName) {
226
231
  (_b = interpreter.globals.form.resolveQualifiedName(fieldIdentifier)) === null || _b === void 0 ? void 0 : _b.markAsInvalid(validationMessage);
227
232
  }
233
+ },
234
+ setFocus: (target, flag) => {
235
+ const args = [target, flag];
236
+ return FunctionRuntimeImpl.getInstance().getFunctions().setFocus._func.call(undefined, args, data, interpreter);
237
+ },
238
+ dispatchEvent: (target, eventName, payload) => {
239
+ const args = [target, eventName, payload];
240
+ return FunctionRuntimeImpl.getInstance().getFunctions().dispatchEvent._func.call(undefined, args, data, interpreter);
228
241
  }
229
242
  }
230
243
  };
@@ -281,7 +294,7 @@ class FunctionRuntimeImpl {
281
294
  validation = interpreter.globals.form.getElement(element.$id).validate();
282
295
  }
283
296
  if (Array.isArray(validation) && validation.length) {
284
- interpreter.globals.form.logger.error('Form Validation Error');
297
+ interpreter.globals.form.logger.warn('Form Validation Error');
285
298
  }
286
299
  return validation;
287
300
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aemforms/af-core",
3
- "version": "0.22.80",
3
+ "version": "0.22.82",
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.80"
40
+ "@aemforms/af-formatters": "^0.22.82"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@babel/preset-env": "^7.20.2",