@aemforms/af-core 0.22.72 → 0.22.74
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.
- package/esm/afb-events.js +6 -1
- package/esm/afb-runtime.js +59 -5
- package/esm/types/src/Checkbox.d.ts +72 -0
- package/esm/types/src/Field.d.ts +2 -1
- package/esm/types/src/FormInstance.d.ts +1 -1
- package/esm/types/src/controller/Events.d.ts +3 -0
- package/esm/types/src/types/Json.d.ts +1 -0
- package/lib/BaseNode.js +2 -1
- package/lib/Checkbox.d.ts +72 -0
- package/lib/Checkbox.js +55 -0
- package/lib/Field.d.ts +2 -1
- package/lib/Field.js +1 -0
- package/lib/Form.js +1 -1
- package/lib/FormInstance.d.ts +1 -1
- package/lib/FormInstance.js +6 -1
- package/lib/controller/Events.d.ts +3 -0
- package/lib/controller/Events.js +7 -1
- package/lib/rules/FunctionRuntime.js +2 -1
- package/lib/types/Json.d.ts +1 -0
- package/package.json +2 -2
package/esm/afb-events.js
CHANGED
|
@@ -116,6 +116,11 @@ class SubmitFailure extends ActionImpl {
|
|
|
116
116
|
super(payload, 'submitFailure', { dispatch });
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
+
class SubmitError extends ActionImpl {
|
|
120
|
+
constructor(payload, dispatch = false) {
|
|
121
|
+
super(payload, 'submitError', { dispatch });
|
|
122
|
+
}
|
|
123
|
+
}
|
|
119
124
|
class Reset extends ActionImpl {
|
|
120
125
|
constructor(payload, dispatch = false) {
|
|
121
126
|
super(payload, 'reset', { dispatch });
|
|
@@ -158,4 +163,4 @@ class RemoveInstance extends ActionImpl {
|
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
165
|
|
|
161
|
-
export { AddInstance, AddItem, Blur, Change, Click, CustomEvent, ExecuteRule, FieldChanged, Focus, FormLoad, Initialize, Invalid, RemoveInstance, RemoveItem, Reset, Submit, SubmitFailure, SubmitSuccess, Valid, ValidationComplete, propertyChange };
|
|
166
|
+
export { AddInstance, AddItem, Blur, Change, Click, CustomEvent, ExecuteRule, FieldChanged, Focus, FormLoad, Initialize, Invalid, RemoveInstance, RemoveItem, Reset, Submit, SubmitError, SubmitFailure, SubmitSuccess, Valid, ValidationComplete, propertyChange };
|
package/esm/afb-runtime.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { propertyChange, ExecuteRule, Initialize, RemoveItem, SubmitSuccess, CustomEvent, SubmitFailure, Submit, RemoveInstance, AddInstance, Reset, AddItem, Click, Change, FormLoad, FieldChanged, ValidationComplete, Valid, Invalid } from './afb-events.js';
|
|
1
|
+
import { propertyChange, ExecuteRule, Initialize, RemoveItem, SubmitSuccess, CustomEvent, SubmitError, SubmitFailure, Submit, RemoveInstance, AddInstance, Reset, AddItem, Click, Change, FormLoad, FieldChanged, ValidationComplete, Valid, Invalid } from './afb-events.js';
|
|
2
2
|
import Formula from '@adobe/json-formula';
|
|
3
3
|
import { parseDefaultDate, datetimeToNumber, format, parseDateSkeleton, formatDate, numberToDatetime } from '@aemforms/af-formatters';
|
|
4
4
|
|
|
@@ -596,7 +596,8 @@ const editableProperties = [
|
|
|
596
596
|
'maximum',
|
|
597
597
|
'maxItems',
|
|
598
598
|
'minimum',
|
|
599
|
-
'minItems'
|
|
599
|
+
'minItems',
|
|
600
|
+
'checked'
|
|
600
601
|
];
|
|
601
602
|
const dynamicProps = [
|
|
602
603
|
...editableProperties,
|
|
@@ -2203,7 +2204,8 @@ const request = async (context, uri, httpVerb, payload, success, error, headers)
|
|
|
2203
2204
|
else {
|
|
2204
2205
|
context.form.logger.error('Error invoking a rest API');
|
|
2205
2206
|
const eName = getCustomEventName(error);
|
|
2206
|
-
if (error === '
|
|
2207
|
+
if (error === 'submitError') {
|
|
2208
|
+
context.form.dispatch(new SubmitError(result, true));
|
|
2207
2209
|
context.form.dispatch(new SubmitFailure(result, true));
|
|
2208
2210
|
}
|
|
2209
2211
|
else {
|
|
@@ -2776,7 +2778,7 @@ class Form extends Container {
|
|
|
2776
2778
|
if (!validate_form || this.validate().length === 0) {
|
|
2777
2779
|
const payload = action?.payload || {};
|
|
2778
2780
|
const successEventName = payload?.success ? payload?.success : 'submitSuccess';
|
|
2779
|
-
const failureEventName = payload?.error ? payload?.error : '
|
|
2781
|
+
const failureEventName = payload?.error ? payload?.error : 'submitError';
|
|
2780
2782
|
submit(context, successEventName, failureEventName, payload?.submit_as, payload?.data);
|
|
2781
2783
|
}
|
|
2782
2784
|
}
|
|
@@ -3449,6 +3451,7 @@ class Field extends Scriptable {
|
|
|
3449
3451
|
}
|
|
3450
3452
|
set required(r) {
|
|
3451
3453
|
this._setProperty('required', r);
|
|
3454
|
+
this.validate();
|
|
3452
3455
|
}
|
|
3453
3456
|
get maximum() {
|
|
3454
3457
|
if (this.type === 'number' || this.format === 'date' || this.type === 'integer') {
|
|
@@ -4077,6 +4080,17 @@ class Checkbox extends Field {
|
|
|
4077
4080
|
baseConstraints.required = requiredConstraint(this.offValue());
|
|
4078
4081
|
return baseConstraints;
|
|
4079
4082
|
}
|
|
4083
|
+
_applyDefaults() {
|
|
4084
|
+
if (typeof this._jsonModel.checked === 'boolean') {
|
|
4085
|
+
if (this._jsonModel.checked) {
|
|
4086
|
+
this._jsonModel.default = this._jsonModel.enum?.[0];
|
|
4087
|
+
}
|
|
4088
|
+
else {
|
|
4089
|
+
this._jsonModel.default = this._jsonModel.enum?.[1];
|
|
4090
|
+
}
|
|
4091
|
+
}
|
|
4092
|
+
super._applyDefaults();
|
|
4093
|
+
}
|
|
4080
4094
|
_getDefaults() {
|
|
4081
4095
|
return {
|
|
4082
4096
|
...super._getDefaults(),
|
|
@@ -4086,7 +4100,43 @@ class Checkbox extends Field {
|
|
|
4086
4100
|
get enum() {
|
|
4087
4101
|
return this._jsonModel.enum || [];
|
|
4088
4102
|
}
|
|
4103
|
+
updateDataNodeAndTypedValue(val) {
|
|
4104
|
+
const changes = super.updateDataNodeAndTypedValue(val);
|
|
4105
|
+
const valueChange = changes.find((c) => c.propertyName === 'value');
|
|
4106
|
+
if (valueChange) {
|
|
4107
|
+
const oldChecked = valueChange.prevValue === this._jsonModel.enum?.[0];
|
|
4108
|
+
const newChecked = valueChange.currentValue === this._jsonModel.enum?.[0];
|
|
4109
|
+
if (oldChecked !== newChecked) {
|
|
4110
|
+
changes.push({
|
|
4111
|
+
propertyName: 'checked',
|
|
4112
|
+
prevValue: oldChecked,
|
|
4113
|
+
currentValue: newChecked
|
|
4114
|
+
});
|
|
4115
|
+
}
|
|
4116
|
+
}
|
|
4117
|
+
return changes;
|
|
4118
|
+
}
|
|
4119
|
+
set checked(check) {
|
|
4120
|
+
if (check) {
|
|
4121
|
+
this.value = this._jsonModel.enum?.[0];
|
|
4122
|
+
}
|
|
4123
|
+
else {
|
|
4124
|
+
this.value = this._jsonModel.enum?.[1];
|
|
4125
|
+
}
|
|
4126
|
+
}
|
|
4127
|
+
get checked() {
|
|
4128
|
+
return this.value === this._jsonModel.enum?.[0];
|
|
4129
|
+
}
|
|
4130
|
+
getState(isRepeatableChild = false, forRestore = false) {
|
|
4131
|
+
return {
|
|
4132
|
+
...super.getState(isRepeatableChild, forRestore),
|
|
4133
|
+
checked: this.checked
|
|
4134
|
+
};
|
|
4135
|
+
}
|
|
4089
4136
|
}
|
|
4137
|
+
__decorate([
|
|
4138
|
+
dependencyTracked()
|
|
4139
|
+
], Checkbox.prototype, "checked", null);
|
|
4090
4140
|
|
|
4091
4141
|
class CheckboxGroup extends Field {
|
|
4092
4142
|
constructor(params, _options) {
|
|
@@ -4258,9 +4308,13 @@ const createFormInstance = (formModel, callback, logLevel = 'error', fModel = un
|
|
|
4258
4308
|
const defaultOptions = {
|
|
4259
4309
|
logLevel: 'error'
|
|
4260
4310
|
};
|
|
4261
|
-
const restoreFormInstance = (formModel, { logLevel } = defaultOptions) => {
|
|
4311
|
+
const restoreFormInstance = (formModel, data = null, { logLevel } = defaultOptions) => {
|
|
4262
4312
|
try {
|
|
4263
4313
|
const form = new Form({ ...formModel }, FormFieldFactory, new RuleEngine(), new EventQueue(new Logger(logLevel)), logLevel, 'restore');
|
|
4314
|
+
if (data) {
|
|
4315
|
+
form._bindToDataModel(new DataGroup('$form', data));
|
|
4316
|
+
form.syncDataAndFormModel(form.getDataNode());
|
|
4317
|
+
}
|
|
4264
4318
|
form.getEventQueue().empty();
|
|
4265
4319
|
return form;
|
|
4266
4320
|
}
|
|
@@ -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/esm/types/src/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
|
-
|
|
54
|
+
protected updateDataNodeAndTypedValue(val: any): any;
|
|
55
55
|
get value(): any;
|
|
56
56
|
set value(v: any);
|
|
57
57
|
reset(): void;
|
|
@@ -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;
|
|
@@ -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>;
|
package/lib/BaseNode.js
CHANGED
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;
|
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
|
-
|
|
54
|
+
protected updateDataNodeAndTypedValue(val: any): any;
|
|
55
55
|
get value(): any;
|
|
56
56
|
set value(v: any);
|
|
57
57
|
reset(): void;
|
|
@@ -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
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 : '
|
|
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
|
}
|
package/lib/FormInstance.d.ts
CHANGED
|
@@ -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;
|
package/lib/FormInstance.js
CHANGED
|
@@ -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
|
}
|
package/lib/controller/Events.js
CHANGED
|
@@ -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 === '
|
|
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 {
|
package/lib/types/Json.d.ts
CHANGED
|
@@ -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>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aemforms/af-core",
|
|
3
|
-
"version": "0.22.
|
|
3
|
+
"version": "0.22.74",
|
|
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.
|
|
40
|
+
"@aemforms/af-formatters": "^0.22.74"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/preset-env": "^7.20.2",
|