@aemforms/af-core 0.22.73 → 0.22.75

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.
@@ -56,14 +56,16 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
56
56
  columnClassNames?: undefined;
57
57
  columnCount?: undefined;
58
58
  gridClassNames?: undefined;
59
+ ':type': string;
60
+ repeatable?: boolean | undefined;
61
+ minOccur?: number | undefined;
62
+ maxOccur?: number | undefined;
59
63
  properties: {
60
64
  [key: string]: any;
61
65
  };
62
66
  index: number;
63
67
  parent: undefined;
64
68
  qualifiedName: any;
65
- repeatable: boolean | undefined;
66
- ':type': string;
67
69
  id: string;
68
70
  };
69
71
  subscribe(callback: callbackFn, eventName?: string): {
@@ -67,6 +67,7 @@ declare class Checkbox extends Field {
67
67
  value: any;
68
68
  };
69
69
  };
70
+ protected _applyDefaults(): void;
70
71
  protected _getDefaults(): {
71
72
  enforceEnum: boolean;
72
73
  readOnly: boolean;
@@ -80,5 +81,76 @@ declare class Checkbox extends Field {
80
81
  type: string | undefined;
81
82
  };
82
83
  get enum(): any[];
84
+ protected updateDataNodeAndTypedValue(val: any): undefined | any;
85
+ set checked(check: boolean);
86
+ get checked(): boolean;
87
+ getState(isRepeatableChild?: boolean, forRestore?: boolean): {
88
+ checked: boolean;
89
+ editFormat: string | undefined;
90
+ displayFormat: string | undefined;
91
+ editValue: any;
92
+ displayValue: any;
93
+ enabled: boolean | undefined;
94
+ readOnly: boolean | undefined;
95
+ description?: string | undefined;
96
+ rules?: import("./types").Items<string> | undefined;
97
+ events?: import("./types").Items<string | string[] | undefined> | undefined;
98
+ enumNames?: string[] | import("./types").EnumName[] | undefined;
99
+ enum?: any[] | undefined;
100
+ accept?: string[] | undefined;
101
+ enforceEnum?: boolean | undefined;
102
+ exclusiveMinimum?: number | undefined;
103
+ exclusiveMaximum?: number | undefined;
104
+ format?: string | undefined;
105
+ maxFileSize?: string | number | undefined;
106
+ maxLength?: number | undefined;
107
+ maximum?: number | undefined;
108
+ maxItems?: number | undefined;
109
+ minOccur?: number | undefined;
110
+ maxOccur?: number | undefined;
111
+ minLength?: number | undefined;
112
+ minimum?: number | undefined;
113
+ minItems?: number | undefined;
114
+ pattern?: string | undefined;
115
+ required?: boolean | undefined;
116
+ step?: number | undefined;
117
+ type?: string | undefined;
118
+ validationExpression?: string | undefined;
119
+ uniqueItems?: boolean | undefined;
120
+ dataRef?: string | null | undefined;
121
+ lang?: string | undefined;
122
+ ':type': string;
123
+ appliedCssClassNames?: string | undefined;
124
+ label?: import("./types").Label | undefined;
125
+ visible?: boolean | undefined;
126
+ name?: string | undefined;
127
+ constraintMessages?: import("./types").ConstraintsMessages | undefined;
128
+ fieldType?: string | undefined;
129
+ errorMessage?: string | undefined;
130
+ properties: {
131
+ [key: string]: any;
132
+ };
133
+ repeatable?: boolean | undefined;
134
+ screenReaderText?: string | undefined;
135
+ tooltip?: string | undefined;
136
+ altText?: string | undefined;
137
+ viewType?: string | undefined;
138
+ placeholder?: string | undefined;
139
+ valid?: boolean | undefined;
140
+ validity?: any;
141
+ validationMessage?: string | undefined;
142
+ default?: any;
143
+ value?: any;
144
+ emptyValue?: "" | "undefined" | "null" | undefined;
145
+ _dependents?: string[] | undefined;
146
+ allowedComponents?: undefined;
147
+ columnClassNames?: undefined;
148
+ columnCount?: undefined;
149
+ gridClassNames?: undefined;
150
+ index: number;
151
+ parent: undefined;
152
+ qualifiedName: any;
153
+ id: string;
154
+ };
83
155
  }
84
156
  export default Checkbox;
@@ -37,14 +37,16 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
37
37
  columnClassNames?: undefined;
38
38
  columnCount?: undefined;
39
39
  gridClassNames?: undefined;
40
+ ':type': string;
41
+ repeatable?: boolean | undefined;
42
+ minOccur?: number | undefined;
43
+ maxOccur?: number | undefined;
40
44
  properties: {
41
45
  [key: string]: any;
42
46
  };
43
47
  index: number;
44
48
  parent: undefined;
45
49
  qualifiedName: any;
46
- repeatable: boolean | undefined;
47
- ':type': string;
48
50
  id: string;
49
51
  };
50
52
  private _createChild;
@@ -51,7 +51,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
51
51
  get editValue(): any;
52
52
  get displayValue(): any;
53
53
  protected getDataNodeValue(typedValue: any): any;
54
- private updateDataNodeAndTypedValue;
54
+ protected updateDataNodeAndTypedValue(val: any): any;
55
55
  get value(): any;
56
56
  set value(v: any);
57
57
  reset(): void;
@@ -197,7 +197,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
197
197
  properties: {
198
198
  [key: string]: any;
199
199
  };
200
- repeatable: boolean | undefined;
200
+ repeatable?: boolean | undefined;
201
201
  screenReaderText?: string | undefined;
202
202
  tooltip?: string | undefined;
203
203
  altText?: string | undefined;
@@ -209,6 +209,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
209
209
  default?: any;
210
210
  value?: any;
211
211
  emptyValue?: "" | "undefined" | "null" | undefined;
212
+ checked?: boolean | undefined;
212
213
  _dependents?: string[] | undefined;
213
214
  allowedComponents?: undefined;
214
215
  columnClassNames?: undefined;
@@ -91,14 +91,16 @@ declare class Form extends Container<FormJson> implements FormModel {
91
91
  columnClassNames?: undefined;
92
92
  columnCount?: undefined;
93
93
  gridClassNames?: undefined;
94
+ ':type': string;
95
+ repeatable?: boolean | undefined;
96
+ minOccur?: number | undefined;
97
+ maxOccur?: number | undefined;
94
98
  properties: {
95
99
  [key: string]: any;
96
100
  };
97
101
  index: number;
98
102
  parent: undefined;
99
103
  qualifiedName: any;
100
- repeatable: boolean | undefined;
101
- ':type': string;
102
104
  id: string;
103
105
  };
104
106
  get type(): string;
@@ -2,7 +2,7 @@ import { FormModel } from './types/index';
2
2
  import { LogLevel } from './controller/Logger';
3
3
  import { CustomFunction, FunctionDefinition } from './rules/FunctionRuntime';
4
4
  export declare const createFormInstance: (formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any) => FormModel;
5
- export declare const restoreFormInstance: (formModel: any, { logLevel }?: {
5
+ export declare const restoreFormInstance: (formModel: any, data?: any, { logLevel }?: {
6
6
  logLevel: LogLevel;
7
7
  }) => FormModel;
8
8
  export declare const validateFormInstance: (formModel: any, data: any) => boolean;
@@ -66,6 +66,9 @@ export declare class SubmitSuccess extends ActionImpl {
66
66
  export declare class SubmitFailure extends ActionImpl {
67
67
  constructor(payload?: any, dispatch?: boolean);
68
68
  }
69
+ export declare class SubmitError extends ActionImpl {
70
+ constructor(payload?: any, dispatch?: boolean);
71
+ }
69
72
  export declare class Reset extends ActionImpl {
70
73
  constructor(payload?: any, dispatch?: boolean);
71
74
  }
@@ -100,6 +100,7 @@ export type FieldJson = BaseJson & TranslationFieldJson & {
100
100
  editValue?: string;
101
101
  displayValue?: string;
102
102
  emptyValue?: 'null' | 'undefined' | '';
103
+ checked?: boolean;
103
104
  };
104
105
  export type ContainerJson = BaseJson & {
105
106
  items: Array<FieldJson | ContainerJson>;
@@ -12,7 +12,8 @@ type ValidConstraintsType = {
12
12
  email: ValidationConstraints[];
13
13
  };
14
14
  export declare const ValidConstraints: ValidConstraintsType;
15
- export type ValidationConstraints = 'type' | 'format' | 'minimum' | 'maximum' | 'exclusiveMinimum' | 'exclusiveMaximum' | 'minItems' | 'maxItems' | 'uniqueItems' | 'minLength' | 'maxLength' | 'pattern' | 'required' | 'enum' | 'accept' | 'maxFileSize';
15
+ export declare const validationConstraintsList: readonly ["type", "format", "minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "minItems", "maxItems", "uniqueItems", "minLength", "maxLength", "pattern", "required", "enum", "accept", "maxFileSize"];
16
+ export type ValidationConstraints = typeof validationConstraintsList[number];
16
17
  type ConstraintsObject = {
17
18
  [key in ValidationConstraints]: (constraint: any, inputVal: any) => ValidationResult;
18
19
  };
package/lib/BaseNode.d.ts CHANGED
@@ -56,14 +56,16 @@ export declare abstract class BaseNode<T extends BaseJson> implements BaseModel
56
56
  columnClassNames?: undefined;
57
57
  columnCount?: undefined;
58
58
  gridClassNames?: undefined;
59
+ ':type': string;
60
+ repeatable?: boolean | undefined;
61
+ minOccur?: number | undefined;
62
+ maxOccur?: number | undefined;
59
63
  properties: {
60
64
  [key: string]: any;
61
65
  };
62
66
  index: number;
63
67
  parent: undefined;
64
68
  qualifiedName: any;
65
- repeatable: boolean | undefined;
66
- ':type': string;
67
69
  id: string;
68
70
  };
69
71
  subscribe(callback: callbackFn, eventName?: string): {
package/lib/BaseNode.js CHANGED
@@ -13,6 +13,7 @@ exports.BaseNode = exports.exclude = exports.include = exports.dependencyTracked
13
13
  const Events_1 = require("./controller/Events");
14
14
  const DataRefParser_1 = require("./utils/DataRefParser");
15
15
  const EmptyDataValue_1 = __importDefault(require("./data/EmptyDataValue"));
16
+ const ValidationUtils_1 = require("./utils/ValidationUtils");
16
17
  exports.editableProperties = [
17
18
  'value',
18
19
  'label',
@@ -31,7 +32,8 @@ exports.editableProperties = [
31
32
  'maximum',
32
33
  'maxItems',
33
34
  'minimum',
34
- 'minItems'
35
+ 'minItems',
36
+ 'checked'
35
37
  ];
36
38
  exports.dynamicProps = [
37
39
  ...exports.editableProperties,
@@ -239,7 +241,11 @@ class BaseNode {
239
241
  return !this._jsonModel.name && !isNonTransparent;
240
242
  }
241
243
  getState(forRestore = false) {
242
- return Object.assign(Object.assign(Object.assign({}, this._jsonModel), { properties: this.properties, index: this.index, parent: undefined, qualifiedName: this.qualifiedName, repeatable: this.repeatable === true ? true : undefined, ':type': this[':type'] }), (forRestore ? {
244
+ return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, this._jsonModel), { properties: this.properties, index: this.index, parent: undefined, qualifiedName: this.qualifiedName }), (this.repeatable === true ? {
245
+ repeatable: true,
246
+ minOccur: this.parent.minItems,
247
+ maxOccur: this.parent.maxItems
248
+ } : {})), { ':type': this[':type'] }), (forRestore ? {
243
249
  _dependents: this._dependents.length ? this._dependents.map(x => x.node.id) : undefined,
244
250
  allowedComponents: undefined,
245
251
  columnClassNames: undefined,
@@ -322,6 +328,9 @@ class BaseNode {
322
328
  this.notifyDependents(changeAction);
323
329
  }
324
330
  notifyChildren.call(this, changeAction);
331
+ if (ValidationUtils_1.validationConstraintsList.includes(prop)) {
332
+ this.validate();
333
+ }
325
334
  return changeAction.payload.changes;
326
335
  }
327
336
  return [];
package/lib/Checkbox.d.ts CHANGED
@@ -67,6 +67,7 @@ declare class Checkbox extends Field {
67
67
  value: any;
68
68
  };
69
69
  };
70
+ protected _applyDefaults(): void;
70
71
  protected _getDefaults(): {
71
72
  enforceEnum: boolean;
72
73
  readOnly: boolean;
@@ -80,5 +81,76 @@ declare class Checkbox extends Field {
80
81
  type: string | undefined;
81
82
  };
82
83
  get enum(): any[];
84
+ protected updateDataNodeAndTypedValue(val: any): undefined | any;
85
+ set checked(check: boolean);
86
+ get checked(): boolean;
87
+ getState(isRepeatableChild?: boolean, forRestore?: boolean): {
88
+ checked: boolean;
89
+ editFormat: string | undefined;
90
+ displayFormat: string | undefined;
91
+ editValue: any;
92
+ displayValue: any;
93
+ enabled: boolean | undefined;
94
+ readOnly: boolean | undefined;
95
+ description?: string | undefined;
96
+ rules?: import("./types").Items<string> | undefined;
97
+ events?: import("./types").Items<string | string[] | undefined> | undefined;
98
+ enumNames?: string[] | import("./types").EnumName[] | undefined;
99
+ enum?: any[] | undefined;
100
+ accept?: string[] | undefined;
101
+ enforceEnum?: boolean | undefined;
102
+ exclusiveMinimum?: number | undefined;
103
+ exclusiveMaximum?: number | undefined;
104
+ format?: string | undefined;
105
+ maxFileSize?: string | number | undefined;
106
+ maxLength?: number | undefined;
107
+ maximum?: number | undefined;
108
+ maxItems?: number | undefined;
109
+ minOccur?: number | undefined;
110
+ maxOccur?: number | undefined;
111
+ minLength?: number | undefined;
112
+ minimum?: number | undefined;
113
+ minItems?: number | undefined;
114
+ pattern?: string | undefined;
115
+ required?: boolean | undefined;
116
+ step?: number | undefined;
117
+ type?: string | undefined;
118
+ validationExpression?: string | undefined;
119
+ uniqueItems?: boolean | undefined;
120
+ dataRef?: string | null | undefined;
121
+ lang?: string | undefined;
122
+ ':type': string;
123
+ appliedCssClassNames?: string | undefined;
124
+ label?: import("./types").Label | undefined;
125
+ visible?: boolean | undefined;
126
+ name?: string | undefined;
127
+ constraintMessages?: import("./types").ConstraintsMessages | undefined;
128
+ fieldType?: string | undefined;
129
+ errorMessage?: string | undefined;
130
+ properties: {
131
+ [key: string]: any;
132
+ };
133
+ repeatable?: boolean | undefined;
134
+ screenReaderText?: string | undefined;
135
+ tooltip?: string | undefined;
136
+ altText?: string | undefined;
137
+ viewType?: string | undefined;
138
+ placeholder?: string | undefined;
139
+ valid?: boolean | undefined;
140
+ validity?: any;
141
+ validationMessage?: string | undefined;
142
+ default?: any;
143
+ value?: any;
144
+ emptyValue?: "" | "undefined" | "null" | undefined;
145
+ _dependents?: string[] | undefined;
146
+ allowedComponents?: undefined;
147
+ columnClassNames?: undefined;
148
+ columnCount?: undefined;
149
+ gridClassNames?: undefined;
150
+ index: number;
151
+ parent: undefined;
152
+ qualifiedName: any;
153
+ id: string;
154
+ };
83
155
  }
84
156
  export default Checkbox;
package/lib/Checkbox.js CHANGED
@@ -1,10 +1,17 @@
1
1
  "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
2
8
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
10
  };
5
11
  Object.defineProperty(exports, "__esModule", { value: true });
6
12
  const Field_1 = __importDefault(require("./Field"));
7
13
  const ValidationUtils_1 = require("./utils/ValidationUtils");
14
+ const BaseNode_1 = require("./BaseNode");
8
15
  const requiredConstraint = (offValue) => (constraint, value) => {
9
16
  const valid = ValidationUtils_1.Constraints.required(constraint, value).valid && (!constraint || value != offValue);
10
17
  return { valid, value };
@@ -19,11 +26,59 @@ class Checkbox extends Field_1.default {
19
26
  baseConstraints.required = requiredConstraint(this.offValue());
20
27
  return baseConstraints;
21
28
  }
29
+ _applyDefaults() {
30
+ var _a, _b;
31
+ if (typeof this._jsonModel.checked === 'boolean') {
32
+ if (this._jsonModel.checked) {
33
+ this._jsonModel.default = (_a = this._jsonModel.enum) === null || _a === void 0 ? void 0 : _a[0];
34
+ }
35
+ else {
36
+ this._jsonModel.default = (_b = this._jsonModel.enum) === null || _b === void 0 ? void 0 : _b[1];
37
+ }
38
+ }
39
+ super._applyDefaults();
40
+ }
22
41
  _getDefaults() {
23
42
  return Object.assign(Object.assign({}, super._getDefaults()), { enforceEnum: true });
24
43
  }
25
44
  get enum() {
26
45
  return this._jsonModel.enum || [];
27
46
  }
47
+ updateDataNodeAndTypedValue(val) {
48
+ var _a, _b;
49
+ const changes = super.updateDataNodeAndTypedValue(val);
50
+ const valueChange = changes.find((c) => c.propertyName === 'value');
51
+ if (valueChange) {
52
+ const oldChecked = valueChange.prevValue === ((_a = this._jsonModel.enum) === null || _a === void 0 ? void 0 : _a[0]);
53
+ const newChecked = valueChange.currentValue === ((_b = this._jsonModel.enum) === null || _b === void 0 ? void 0 : _b[0]);
54
+ if (oldChecked !== newChecked) {
55
+ changes.push({
56
+ propertyName: 'checked',
57
+ prevValue: oldChecked,
58
+ currentValue: newChecked
59
+ });
60
+ }
61
+ }
62
+ return changes;
63
+ }
64
+ set checked(check) {
65
+ var _a, _b;
66
+ if (check) {
67
+ this.value = (_a = this._jsonModel.enum) === null || _a === void 0 ? void 0 : _a[0];
68
+ }
69
+ else {
70
+ this.value = (_b = this._jsonModel.enum) === null || _b === void 0 ? void 0 : _b[1];
71
+ }
72
+ }
73
+ get checked() {
74
+ var _a;
75
+ return this.value === ((_a = this._jsonModel.enum) === null || _a === void 0 ? void 0 : _a[0]);
76
+ }
77
+ getState(isRepeatableChild = false, forRestore = false) {
78
+ return Object.assign(Object.assign({}, super.getState(isRepeatableChild, forRestore)), { checked: this.checked });
79
+ }
28
80
  }
81
+ __decorate([
82
+ (0, BaseNode_1.dependencyTracked)()
83
+ ], Checkbox.prototype, "checked", null);
29
84
  exports.default = Checkbox;
@@ -37,14 +37,16 @@ declare abstract class Container<T extends ContainerJson & RulesJson> extends Sc
37
37
  columnClassNames?: undefined;
38
38
  columnCount?: undefined;
39
39
  gridClassNames?: undefined;
40
+ ':type': string;
41
+ repeatable?: boolean | undefined;
42
+ minOccur?: number | undefined;
43
+ maxOccur?: number | undefined;
40
44
  properties: {
41
45
  [key: string]: any;
42
46
  };
43
47
  index: number;
44
48
  parent: undefined;
45
49
  qualifiedName: any;
46
- repeatable: boolean | undefined;
47
- ':type': string;
48
50
  id: string;
49
51
  };
50
52
  private _createChild;
package/lib/Field.d.ts CHANGED
@@ -51,7 +51,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
51
51
  get editValue(): any;
52
52
  get displayValue(): any;
53
53
  protected getDataNodeValue(typedValue: any): any;
54
- private updateDataNodeAndTypedValue;
54
+ protected updateDataNodeAndTypedValue(val: any): any;
55
55
  get value(): any;
56
56
  set value(v: any);
57
57
  reset(): void;
@@ -197,7 +197,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
197
197
  properties: {
198
198
  [key: string]: any;
199
199
  };
200
- repeatable: boolean | undefined;
200
+ repeatable?: boolean | undefined;
201
201
  screenReaderText?: string | undefined;
202
202
  tooltip?: string | undefined;
203
203
  altText?: string | undefined;
@@ -209,6 +209,7 @@ declare class Field extends Scriptable<FieldJson> implements FieldModel {
209
209
  default?: any;
210
210
  value?: any;
211
211
  emptyValue?: "" | "undefined" | "null" | undefined;
212
+ checked?: boolean | undefined;
212
213
  _dependents?: string[] | undefined;
213
214
  allowedComponents?: undefined;
214
215
  columnClassNames?: undefined;
package/lib/Field.js CHANGED
@@ -244,7 +244,6 @@ class Field extends Scriptable_1.default {
244
244
  }
245
245
  set required(r) {
246
246
  this._setProperty('required', r);
247
- this.validate();
248
247
  }
249
248
  get maximum() {
250
249
  if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
package/lib/Form.d.ts CHANGED
@@ -91,14 +91,16 @@ declare class Form extends Container<FormJson> implements FormModel {
91
91
  columnClassNames?: undefined;
92
92
  columnCount?: undefined;
93
93
  gridClassNames?: undefined;
94
+ ':type': string;
95
+ repeatable?: boolean | undefined;
96
+ minOccur?: number | undefined;
97
+ maxOccur?: number | undefined;
94
98
  properties: {
95
99
  [key: string]: any;
96
100
  };
97
101
  index: number;
98
102
  parent: undefined;
99
103
  qualifiedName: any;
100
- repeatable: boolean | undefined;
101
- ':type': string;
102
104
  id: string;
103
105
  };
104
106
  get type(): string;
package/lib/Form.js CHANGED
@@ -217,7 +217,7 @@ class Form extends Container_1.default {
217
217
  if (!validate_form || this.validate().length === 0) {
218
218
  const payload = (action === null || action === void 0 ? void 0 : action.payload) || {};
219
219
  const successEventName = (payload === null || payload === void 0 ? void 0 : payload.success) ? payload === null || payload === void 0 ? void 0 : payload.success : 'submitSuccess';
220
- const failureEventName = (payload === null || payload === void 0 ? void 0 : payload.error) ? payload === null || payload === void 0 ? void 0 : payload.error : 'submitFailure';
220
+ const failureEventName = (payload === null || payload === void 0 ? void 0 : payload.error) ? payload === null || payload === void 0 ? void 0 : payload.error : 'submitError';
221
221
  (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);
222
222
  }
223
223
  }
@@ -2,7 +2,7 @@ import { FormModel } from './types/index';
2
2
  import { LogLevel } from './controller/Logger';
3
3
  import { CustomFunction, FunctionDefinition } from './rules/FunctionRuntime';
4
4
  export declare const createFormInstance: (formModel: any, callback?: ((f: FormModel) => any) | undefined, logLevel?: LogLevel, fModel?: any) => FormModel;
5
- export declare const restoreFormInstance: (formModel: any, { logLevel }?: {
5
+ export declare const restoreFormInstance: (formModel: any, data?: any, { logLevel }?: {
6
6
  logLevel: LogLevel;
7
7
  }) => FormModel;
8
8
  export declare const validateFormInstance: (formModel: any, data: any) => boolean;
@@ -13,6 +13,7 @@ const Logger_1 = require("./controller/Logger");
13
13
  const FormCreationUtils_1 = require("./utils/FormCreationUtils");
14
14
  const FunctionRuntime_1 = require("./rules/FunctionRuntime");
15
15
  const FormUtils_1 = require("./utils/FormUtils");
16
+ const DataGroup_1 = __importDefault(require("./data/DataGroup"));
16
17
  const createFormInstance = (formModel, callback, logLevel = 'error', fModel = undefined) => {
17
18
  try {
18
19
  let f = fModel;
@@ -39,9 +40,13 @@ exports.createFormInstance = createFormInstance;
39
40
  const defaultOptions = {
40
41
  logLevel: 'error'
41
42
  };
42
- const restoreFormInstance = (formModel, { logLevel } = defaultOptions) => {
43
+ const restoreFormInstance = (formModel, data = null, { logLevel } = defaultOptions) => {
43
44
  try {
44
45
  const form = new Form_1.default(Object.assign({}, formModel), FormCreationUtils_1.FormFieldFactory, new RuleEngine_1.default(), new EventQueue_1.default(new Logger_1.Logger(logLevel)), logLevel, 'restore');
46
+ if (data) {
47
+ form._bindToDataModel(new DataGroup_1.default('$form', data));
48
+ form.syncDataAndFormModel(form.getDataNode());
49
+ }
45
50
  form.getEventQueue().empty();
46
51
  return form;
47
52
  }
@@ -66,6 +66,9 @@ export declare class SubmitSuccess extends ActionImpl {
66
66
  export declare class SubmitFailure extends ActionImpl {
67
67
  constructor(payload?: any, dispatch?: boolean);
68
68
  }
69
+ export declare class SubmitError extends ActionImpl {
70
+ constructor(payload?: any, dispatch?: boolean);
71
+ }
69
72
  export declare class Reset extends ActionImpl {
70
73
  constructor(payload?: any, dispatch?: boolean);
71
74
  }
@@ -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.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;
3
+ exports.RemoveInstance = exports.AddInstance = exports.RemoveItem = exports.AddItem = exports.CustomEvent = exports.FieldChanged = exports.Reset = exports.SubmitError = 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;
@@ -129,6 +129,12 @@ class SubmitFailure extends ActionImpl {
129
129
  }
130
130
  }
131
131
  exports.SubmitFailure = SubmitFailure;
132
+ class SubmitError extends ActionImpl {
133
+ constructor(payload, dispatch = false) {
134
+ super(payload, 'submitError', { dispatch });
135
+ }
136
+ }
137
+ exports.SubmitError = SubmitError;
132
138
  class Reset extends ActionImpl {
133
139
  constructor(payload, dispatch = false) {
134
140
  super(payload, 'reset', { dispatch });
@@ -69,7 +69,8 @@ const request = (context, uri, httpVerb, payload, success, error, headers) => __
69
69
  else {
70
70
  context.form.logger.error('Error invoking a rest API');
71
71
  const eName = getCustomEventName(error);
72
- if (error === 'submitFailure') {
72
+ if (error === 'submitError') {
73
+ context.form.dispatch(new Events_1.SubmitError(result, true));
73
74
  context.form.dispatch(new Events_1.SubmitFailure(result, true));
74
75
  }
75
76
  else {
@@ -201,6 +202,11 @@ class FunctionRuntimeImpl {
201
202
  },
202
203
  exportData: () => {
203
204
  return FunctionRuntimeImpl.getInstance().getFunctions().exportData._func.call(undefined, args, data, interpreter);
205
+ },
206
+ submitForm: (payload, validateForm, contentType) => {
207
+ const submitAs = contentType || 'multipart/form-data';
208
+ const args = ['custom:submitSuccess', 'custom:submitError', submitAs, payload, validateForm];
209
+ return FunctionRuntimeImpl.getInstance().getFunctions().submitForm._func.call(undefined, args, data, interpreter);
204
210
  }
205
211
  }
206
212
  };
@@ -302,11 +308,24 @@ class FunctionRuntimeImpl {
302
308
  },
303
309
  submitForm: {
304
310
  _func: (args, data, interpreter) => {
305
- const success = toString(args[0]);
306
- const error = toString(args[1]);
307
- const submit_as = args.length > 2 ? toString(args[2]) : 'multipart/form-data';
308
- const submit_data = args.length > 3 ? valueOf(args[3]) : null;
309
- const validate_form = args.length > 4 ? valueOf(args[4]) : true;
311
+ let success = 'custom:submitSuccess';
312
+ let error = 'custom:submitError';
313
+ let submit_data;
314
+ let validate_form;
315
+ let submit_as;
316
+ if (args.length > 0 && typeof valueOf(args[0]) === 'object') {
317
+ submit_data = args.length > 0 ? valueOf(args[0]) : null;
318
+ validate_form = args.length > 1 ? valueOf(args[1]) : true;
319
+ submit_as = args.length > 2 ? toString(args[2]) : 'multipart/form-data';
320
+ }
321
+ else {
322
+ interpreter.globals.form.logger.warn('This usage of submitForm is deprecated. Please see the documentation and update');
323
+ success = toString(args[0]);
324
+ error = toString(args[1]);
325
+ submit_as = args.length > 2 ? toString(args[2]) : 'multipart/form-data';
326
+ submit_data = args.length > 3 ? valueOf(args[3]) : null;
327
+ validate_form = args.length > 4 ? valueOf(args[4]) : true;
328
+ }
310
329
  interpreter.globals.form.dispatch(new Events_1.Submit({
311
330
  success,
312
331
  error,
@@ -100,6 +100,7 @@ export declare type FieldJson = BaseJson & TranslationFieldJson & {
100
100
  editValue?: string;
101
101
  displayValue?: string;
102
102
  emptyValue?: 'null' | 'undefined' | '';
103
+ checked?: boolean;
103
104
  };
104
105
  export declare type ContainerJson = BaseJson & {
105
106
  items: Array<FieldJson | ContainerJson>;