@formio/js 5.0.0-rc.38 → 5.0.0-rc.40
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/formio.builder.css +2 -2
- package/dist/formio.builder.min.css +1 -1
- package/dist/formio.embed.js +1 -1
- package/dist/formio.embed.min.js +1 -1
- package/dist/formio.embed.min.js.LICENSE.txt +1 -1
- package/dist/formio.form.css +2 -2
- package/dist/formio.form.js +5335 -2376
- package/dist/formio.form.min.css +1 -1
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.form.min.js.LICENSE.txt +23 -5
- package/dist/formio.full.css +2 -2
- package/dist/formio.full.js +5663 -2696
- package/dist/formio.full.min.css +1 -1
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.full.min.js.LICENSE.txt +23 -5
- package/dist/formio.js +72 -62
- package/dist/formio.min.js +1 -1
- package/dist/formio.min.js.LICENSE.txt +1 -1
- package/dist/formio.utils.js +105 -96
- package/dist/formio.utils.min.js +1 -1
- package/dist/formio.utils.min.js.LICENSE.txt +4 -4
- package/lib/cjs/Element.js +1 -0
- package/lib/cjs/Embed.js +134 -131
- package/lib/cjs/Webform.js +36 -13
- package/lib/cjs/WebformBuilder.js +4 -2
- package/lib/cjs/Wizard.js +6 -1
- package/lib/cjs/components/_classes/component/Component.js +33 -22
- package/lib/cjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
- package/lib/cjs/components/_classes/component/editForm/Component.edit.validation.js +8 -0
- package/lib/cjs/components/_classes/component/fixtures/comp5.js +2 -2
- package/lib/cjs/components/_classes/multivalue/Multivalue.js +2 -2
- package/lib/cjs/components/_classes/nested/NestedComponent.js +2 -2
- package/lib/cjs/components/address/fixtures/comp3.js +1 -1
- package/lib/cjs/components/builder.js +0 -2
- package/lib/cjs/components/button/Button.js +7 -1
- package/lib/cjs/components/datagrid/DataGrid.js +16 -3
- package/lib/cjs/components/datagrid/fixtures/comp-with-allow-calculate-override.js +68 -0
- package/lib/cjs/components/datagrid/fixtures/comp6.js +1 -1
- package/lib/cjs/components/datagrid/fixtures/index.js +5 -1
- package/lib/cjs/components/datagrid/fixtures/two-comp-with-allow-calculate-override.js +104 -0
- package/lib/cjs/components/editgrid/EditGrid.js +11 -4
- package/lib/cjs/components/editgrid/fixtures/formsWithEditGridAndConditions.js +923 -0
- package/lib/cjs/components/file/File.js +2 -2
- package/lib/cjs/components/file/editForm/File.edit.file.js +1 -1
- package/lib/cjs/components/form/Form.js +1 -1
- package/lib/cjs/components/html/HTML.js +11 -2
- package/lib/cjs/components/html/fixtures/index.js +1 -3
- package/lib/cjs/components/index.js +0 -2
- package/lib/cjs/components/recaptcha/ReCaptcha.js +46 -46
- package/lib/cjs/components/select/Select.js +3 -1
- package/lib/cjs/components/select/fixtures/comp20.js +46 -0
- package/lib/cjs/components/select/fixtures/comp21.js +106 -0
- package/lib/cjs/components/select/fixtures/index.js +5 -1
- package/lib/cjs/components/selectboxes/SelectBoxes.js +1 -1
- package/lib/cjs/components/textfield/TextField.js +63 -3
- package/lib/cjs/providers/storage/s3.js +5 -3
- package/lib/cjs/providers/storage/uploadAdapter.js +1 -1
- package/lib/cjs/providers/storage/url.js +19 -13
- package/lib/cjs/providers/storage/util.js +2 -2
- package/lib/cjs/templates/Templates.js +4 -4
- package/lib/cjs/translations/en.js +10 -6
- package/lib/cjs/utils/Evaluator.js +1 -1
- package/lib/cjs/utils/conditionOperators/IsEqualTo.js +1 -1
- package/lib/cjs/utils/formUtils.js +3 -3
- package/lib/cjs/utils/utils.js +4 -19
- package/lib/cjs/widgets/CalendarWidget.js +1 -1
- package/lib/mjs/Element.js +1 -0
- package/lib/mjs/Embed.js +10 -8
- package/lib/mjs/FormBuilder.js +1 -2
- package/lib/mjs/Webform.js +36 -13
- package/lib/mjs/WebformBuilder.js +4 -2
- package/lib/mjs/Wizard.js +6 -1
- package/lib/mjs/builders/Builders.js +1 -2
- package/lib/mjs/components/Components.js +1 -2
- package/lib/mjs/components/_classes/component/Component.js +33 -24
- package/lib/mjs/components/_classes/component/editForm/Component.edit.logic.js +1 -1
- package/lib/mjs/components/_classes/component/editForm/Component.edit.validation.js +8 -0
- package/lib/mjs/components/_classes/component/fixtures/comp5.js +2 -2
- package/lib/mjs/components/_classes/multivalue/Multivalue.js +2 -2
- package/lib/mjs/components/_classes/nested/NestedComponent.js +2 -2
- package/lib/mjs/components/address/fixtures/comp3.js +1 -1
- package/lib/mjs/components/builder.js +0 -2
- package/lib/mjs/components/button/Button.js +7 -1
- package/lib/mjs/components/datagrid/DataGrid.js +15 -3
- package/lib/mjs/components/datagrid/fixtures/comp-with-allow-calculate-override.js +66 -0
- package/lib/mjs/components/datagrid/fixtures/comp6.js +1 -1
- package/lib/mjs/components/datagrid/fixtures/index.js +3 -1
- package/lib/mjs/components/datagrid/fixtures/two-comp-with-allow-calculate-override.js +102 -0
- package/lib/mjs/components/editgrid/EditGrid.js +11 -4
- package/lib/mjs/components/editgrid/fixtures/formsWithEditGridAndConditions.js +921 -0
- package/lib/mjs/components/file/File.js +2 -2
- package/lib/mjs/components/file/editForm/File.edit.file.js +1 -1
- package/lib/mjs/components/form/Form.js +1 -1
- package/lib/mjs/components/html/HTML.js +10 -2
- package/lib/mjs/components/html/fixtures/index.js +1 -2
- package/lib/mjs/components/index.js +0 -2
- package/lib/mjs/components/recaptcha/ReCaptcha.js +32 -43
- package/lib/mjs/components/select/Select.js +3 -1
- package/lib/mjs/components/select/fixtures/comp20.js +44 -0
- package/lib/mjs/components/select/fixtures/comp21.js +104 -0
- package/lib/mjs/components/select/fixtures/index.js +3 -1
- package/lib/mjs/components/selectboxes/SelectBoxes.js +1 -1
- package/lib/mjs/components/textfield/TextField.js +62 -3
- package/lib/mjs/displays/Displays.js +1 -2
- package/lib/mjs/licenses/Licenses.js +1 -2
- package/lib/mjs/providers/Providers.js +1 -2
- package/lib/mjs/providers/storage/s3.js +5 -3
- package/lib/mjs/providers/storage/uploadAdapter.js +1 -1
- package/lib/mjs/providers/storage/url.js +19 -13
- package/lib/mjs/templates/Templates.js +1 -1
- package/lib/mjs/translations/en.js +10 -6
- package/lib/mjs/utils/Evaluator.js +1 -1
- package/lib/mjs/utils/conditionOperators/IsEqualTo.js +1 -1
- package/lib/mjs/utils/formUtils.js +3 -3
- package/lib/mjs/utils/utils.js +2 -16
- package/lib/mjs/widgets/CalendarWidget.js +1 -1
- package/package.json +21 -20
- package/lib/cjs/components/html/fixtures/comp3.js +0 -31
- package/lib/cjs/components/resource/Resource.form.js +0 -16
- package/lib/cjs/components/resource/Resource.js +0 -39
- package/lib/cjs/components/resource/editForm/Resource.edit.display.js +0 -102
- package/lib/cjs/components/resource/fixtures/comp1.js +0 -30
- package/lib/cjs/components/resource/fixtures/comp2.js +0 -31
- package/lib/cjs/components/resource/fixtures/index.js +0 -10
- package/lib/mjs/components/html/fixtures/comp3.js +0 -29
- package/lib/mjs/components/resource/Resource.form.js +0 -10
- package/lib/mjs/components/resource/Resource.js +0 -33
- package/lib/mjs/components/resource/editForm/Resource.edit.display.js +0 -100
- package/lib/mjs/components/resource/fixtures/comp1.js +0 -28
- package/lib/mjs/components/resource/fixtures/comp2.js +0 -29
- package/lib/mjs/components/resource/fixtures/index.js +0 -3
@@ -10,11 +10,11 @@
|
|
10
10
|
* MIT licensed
|
11
11
|
*/
|
12
12
|
|
13
|
-
/*! @license DOMPurify 3.0.7 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.7/LICENSE */
|
14
|
-
|
15
13
|
/*! @license DOMPurify 3.0.8 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.8/LICENSE */
|
16
14
|
|
17
|
-
/*!
|
15
|
+
/*! @license DOMPurify 3.0.9 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.0.9/LICENSE */
|
16
|
+
|
17
|
+
/*! formiojs v5.0.0-rc.40 | https://unpkg.com/formiojs@5.0.0-rc.40/LICENSE.txt */
|
18
18
|
|
19
19
|
/**
|
20
20
|
* @license
|
@@ -35,4 +35,4 @@
|
|
35
35
|
|
36
36
|
//! moment.js
|
37
37
|
|
38
|
-
//! version : 0.5.
|
38
|
+
//! version : 0.5.45
|
package/lib/cjs/Element.js
CHANGED
@@ -539,6 +539,7 @@ class Element {
|
|
539
539
|
token: Formio_1.Formio.getToken({
|
540
540
|
decode: true
|
541
541
|
}),
|
542
|
+
options: this.options,
|
542
543
|
config: this.root && this.root.form && this.root.form.config
|
543
544
|
? this.root.form.config
|
544
545
|
: ((_a = this.options) === null || _a === void 0 ? void 0 : _a.formConfig)
|
package/lib/cjs/Embed.js
CHANGED
@@ -17,49 +17,49 @@ exports.FormBuilder = exports.Form = exports.Formio = void 0;
|
|
17
17
|
const CDN_js_1 = __importDefault(require("./CDN.js"));
|
18
18
|
class Formio {
|
19
19
|
static setLicense(license, norecurse = false) {
|
20
|
-
|
21
|
-
if (!norecurse &&
|
22
|
-
|
20
|
+
_a.license = license;
|
21
|
+
if (!norecurse && _a.FormioClass) {
|
22
|
+
_a.FormioClass.setLicense(license);
|
23
23
|
}
|
24
24
|
}
|
25
25
|
static setBaseUrl(url, norecurse = false) {
|
26
|
-
|
27
|
-
if (!norecurse &&
|
28
|
-
|
26
|
+
_a.baseUrl = url;
|
27
|
+
if (!norecurse && _a.FormioClass) {
|
28
|
+
_a.FormioClass.setBaseUrl(url);
|
29
29
|
}
|
30
30
|
}
|
31
31
|
static setApiUrl(url, norecurse = false) {
|
32
|
-
|
33
|
-
if (!norecurse &&
|
34
|
-
|
32
|
+
_a.baseUrl = url;
|
33
|
+
if (!norecurse && _a.FormioClass) {
|
34
|
+
_a.FormioClass.setApiUrl(url);
|
35
35
|
}
|
36
36
|
}
|
37
37
|
static setProjectUrl(url, norecurse = false) {
|
38
|
-
|
39
|
-
if (!norecurse &&
|
40
|
-
|
38
|
+
_a.projectUrl = url;
|
39
|
+
if (!norecurse && _a.FormioClass) {
|
40
|
+
_a.FormioClass.setProjectUrl(url);
|
41
41
|
}
|
42
42
|
}
|
43
43
|
static setAppUrl(url, norecurse = false) {
|
44
|
-
|
45
|
-
if (!norecurse &&
|
46
|
-
|
44
|
+
_a.projectUrl = url;
|
45
|
+
if (!norecurse && _a.FormioClass) {
|
46
|
+
_a.FormioClass.setAppUrl(url);
|
47
47
|
}
|
48
48
|
}
|
49
49
|
static setPathType(type, norecurse = false) {
|
50
|
-
|
51
|
-
if (!norecurse &&
|
52
|
-
|
50
|
+
_a.pathType = type;
|
51
|
+
if (!norecurse && _a.FormioClass) {
|
52
|
+
_a.FormioClass.setPathType(type);
|
53
53
|
}
|
54
54
|
}
|
55
55
|
static debug(...args) {
|
56
|
-
if (
|
56
|
+
if (_a.config.debug) {
|
57
57
|
console.log(...args);
|
58
58
|
}
|
59
59
|
}
|
60
60
|
static clearCache() {
|
61
|
-
if (
|
62
|
-
|
61
|
+
if (_a.FormioClass) {
|
62
|
+
_a.FormioClass.clearCache();
|
63
63
|
}
|
64
64
|
}
|
65
65
|
static global(prop, flag = '') {
|
@@ -67,15 +67,15 @@ class Formio {
|
|
67
67
|
if (flag && globalValue && !globalValue[flag]) {
|
68
68
|
return null;
|
69
69
|
}
|
70
|
-
|
70
|
+
_a.debug(`Getting global ${prop}`, globalValue);
|
71
71
|
return globalValue;
|
72
72
|
}
|
73
73
|
static use(module) {
|
74
|
-
if (
|
75
|
-
|
74
|
+
if (_a.FormioClass && _a.FormioClass.isRenderer) {
|
75
|
+
_a.FormioClass.use(module);
|
76
76
|
}
|
77
77
|
else {
|
78
|
-
|
78
|
+
_a.modules.push(module);
|
79
79
|
}
|
80
80
|
}
|
81
81
|
static createElement(type, attrs, children) {
|
@@ -84,42 +84,42 @@ class Formio {
|
|
84
84
|
element.setAttribute(key, attrs[key]);
|
85
85
|
});
|
86
86
|
(children || []).forEach(child => {
|
87
|
-
element.appendChild(
|
87
|
+
element.appendChild(_a.createElement(child.tag, child.attrs, child.children));
|
88
88
|
});
|
89
89
|
return element;
|
90
90
|
}
|
91
|
-
static addScript(
|
92
|
-
return __awaiter(this,
|
91
|
+
static addScript(wrapper_1, src_1, name_1) {
|
92
|
+
return __awaiter(this, arguments, void 0, function* (wrapper, src, name, flag = '') {
|
93
93
|
if (!src) {
|
94
94
|
return Promise.resolve();
|
95
95
|
}
|
96
96
|
if (typeof src !== 'string' && src.length) {
|
97
|
-
return Promise.all(src.map(ref =>
|
97
|
+
return Promise.all(src.map(ref => _a.addScript(wrapper, ref)));
|
98
98
|
}
|
99
|
-
if (name &&
|
100
|
-
|
101
|
-
return Promise.resolve(
|
99
|
+
if (name && _a.global(name, flag)) {
|
100
|
+
_a.debug(`${name} already loaded.`);
|
101
|
+
return Promise.resolve(_a.global(name));
|
102
102
|
}
|
103
|
-
|
103
|
+
_a.debug('Adding Script', src);
|
104
104
|
try {
|
105
|
-
wrapper.appendChild(
|
105
|
+
wrapper.appendChild(_a.createElement('script', {
|
106
106
|
src
|
107
107
|
}));
|
108
108
|
}
|
109
109
|
catch (err) {
|
110
|
-
|
110
|
+
_a.debug(err);
|
111
111
|
return Promise.resolve();
|
112
112
|
}
|
113
113
|
if (!name) {
|
114
114
|
return Promise.resolve();
|
115
115
|
}
|
116
116
|
return new Promise((resolve) => {
|
117
|
-
|
117
|
+
_a.debug(`Waiting to load ${name}`);
|
118
118
|
const wait = setInterval(() => {
|
119
|
-
if (
|
119
|
+
if (_a.global(name, flag)) {
|
120
120
|
clearInterval(wait);
|
121
|
-
|
122
|
-
resolve(
|
121
|
+
_a.debug(`${name} loaded.`);
|
122
|
+
resolve(_a.global(name));
|
123
123
|
}
|
124
124
|
}, 100);
|
125
125
|
});
|
@@ -131,11 +131,11 @@ class Formio {
|
|
131
131
|
return;
|
132
132
|
}
|
133
133
|
if (typeof href !== 'string' && href.length) {
|
134
|
-
href.forEach(ref =>
|
134
|
+
href.forEach(ref => _a.addStyles(wrapper, ref));
|
135
135
|
return;
|
136
136
|
}
|
137
|
-
|
138
|
-
wrapper.appendChild(
|
137
|
+
_a.debug('Adding Styles', href);
|
138
|
+
wrapper.appendChild(_a.createElement('link', {
|
139
139
|
rel: 'stylesheet',
|
140
140
|
href
|
141
141
|
}));
|
@@ -143,19 +143,19 @@ class Formio {
|
|
143
143
|
}
|
144
144
|
static submitDone(instance, submission) {
|
145
145
|
return __awaiter(this, void 0, void 0, function* () {
|
146
|
-
|
147
|
-
const successMessage = (
|
146
|
+
_a.debug('Submision Complete', submission);
|
147
|
+
const successMessage = (_a.config.success || '').toString();
|
148
148
|
if (successMessage && successMessage.toLowerCase() !== 'false' && instance.element) {
|
149
149
|
instance.element.innerHTML = `<div class="alert-success" role="alert">${successMessage}</div>`;
|
150
150
|
}
|
151
|
-
let returnUrl =
|
151
|
+
let returnUrl = _a.config.redirect;
|
152
152
|
// Allow form based configuration for return url.
|
153
153
|
if (!returnUrl &&
|
154
154
|
(instance._form &&
|
155
155
|
instance._form.settings &&
|
156
156
|
(instance._form.settings.returnUrl ||
|
157
157
|
instance._form.settings.redirect))) {
|
158
|
-
|
158
|
+
_a.debug('Return url found in form configuration');
|
159
159
|
returnUrl = instance._form.settings.returnUrl || instance._form.settings.redirect;
|
160
160
|
}
|
161
161
|
if (returnUrl) {
|
@@ -167,7 +167,7 @@ class Formio {
|
|
167
167
|
if (!isOrigin && formSrc) {
|
168
168
|
returnUrl += `&form=${encodeURIComponent(formSrc)}`;
|
169
169
|
}
|
170
|
-
|
170
|
+
_a.debug('Return URL', returnUrl);
|
171
171
|
window.location.href = returnUrl;
|
172
172
|
if (isOrigin) {
|
173
173
|
window.location.reload();
|
@@ -177,9 +177,9 @@ class Formio {
|
|
177
177
|
}
|
178
178
|
// Return the full script if the builder is being used.
|
179
179
|
static formioScript(script, builder) {
|
180
|
-
builder = builder ||
|
181
|
-
if (
|
182
|
-
|
180
|
+
builder = builder || _a.config.includeBuilder;
|
181
|
+
if (_a.fullAdded || builder) {
|
182
|
+
_a.fullAdded = true;
|
183
183
|
return script.replace('formio.form', 'formio.full');
|
184
184
|
}
|
185
185
|
return script;
|
@@ -191,28 +191,28 @@ class Formio {
|
|
191
191
|
}
|
192
192
|
if (lib.dependencies) {
|
193
193
|
for (let i = 0; i < lib.dependencies.length; i++) {
|
194
|
-
yield
|
194
|
+
yield _a.addLibrary(wrapper, _a.cdn.libs[lib.dependencies[i]]);
|
195
195
|
}
|
196
196
|
}
|
197
197
|
if (lib.css) {
|
198
|
-
yield
|
198
|
+
yield _a.addStyles(wrapper, lib.css);
|
199
199
|
}
|
200
200
|
if (lib.js) {
|
201
|
-
const module = yield
|
201
|
+
const module = yield _a.addScript(wrapper, lib.js, lib.use ? name : false);
|
202
202
|
if (lib.use) {
|
203
|
-
|
203
|
+
_a.debug(`Using ${name}`);
|
204
204
|
const options = lib.options || {};
|
205
|
-
if (!options.license &&
|
206
|
-
options.license =
|
205
|
+
if (!options.license && _a.license) {
|
206
|
+
options.license = _a.license;
|
207
207
|
}
|
208
|
-
|
208
|
+
_a.use((typeof lib.use === 'function' ? lib.use(module) : module), options);
|
209
209
|
}
|
210
210
|
}
|
211
211
|
});
|
212
212
|
}
|
213
213
|
static addLoader(wrapper) {
|
214
214
|
return __awaiter(this, void 0, void 0, function* () {
|
215
|
-
wrapper.appendChild(
|
215
|
+
wrapper.appendChild(_a.createElement('div', {
|
216
216
|
'class': 'formio-loader'
|
217
217
|
}, [{
|
218
218
|
tag: 'div',
|
@@ -229,39 +229,40 @@ class Formio {
|
|
229
229
|
});
|
230
230
|
}
|
231
231
|
// eslint-disable-next-line max-statements
|
232
|
-
static init(
|
233
|
-
return __awaiter(this,
|
234
|
-
|
235
|
-
|
232
|
+
static init(element_1) {
|
233
|
+
return __awaiter(this, arguments, void 0, function* (element, options = {}, builder = false) {
|
234
|
+
_a.cdn = new CDN_js_1.default(_a.config.cdn, _a.config.cdnUrls || {});
|
235
|
+
_a.config.libs = _a.config.libs || {
|
236
236
|
uswds: {
|
237
237
|
dependencies: ['fontawesome'],
|
238
|
-
js: `${
|
239
|
-
css: `${
|
238
|
+
js: `${_a.cdn.uswds}/uswds.min.js`,
|
239
|
+
css: `${_a.cdn.uswds}/uswds.min.css`,
|
240
240
|
use: true
|
241
241
|
},
|
242
242
|
fontawesome: {
|
243
|
-
css: `${
|
243
|
+
css: `${_a.cdn['font-awesome']}/css/font-awesome.min.css`
|
244
244
|
},
|
245
245
|
bootstrap4: {
|
246
246
|
dependencies: ['fontawesome'],
|
247
|
-
css: `${
|
247
|
+
css: `${_a.cdn.bootstrap4}/css/bootstrap.min.css`
|
248
248
|
},
|
249
249
|
bootstrap: {
|
250
250
|
dependencies: ['bootstrap-icons'],
|
251
|
-
css: `${
|
251
|
+
css: `${_a.cdn.bootstrap}/css/bootstrap.min.css`
|
252
252
|
},
|
253
253
|
'bootstrap-icons': {
|
254
|
-
css: `${
|
254
|
+
css: `${_a.cdn['bootstrap-icons']}/css/bootstrap-icons.css`
|
255
255
|
}
|
256
256
|
};
|
257
|
-
const id =
|
257
|
+
const id = _a.config.id || `formio-${Math.random().toString(36).substring(7)}`;
|
258
258
|
// Create a new wrapper and add the element inside of a new wrapper.
|
259
|
-
let wrapper =
|
259
|
+
let wrapper = _a.createElement('div', {
|
260
260
|
'id': `${id}-wrapper`
|
261
261
|
});
|
262
262
|
element.parentNode.insertBefore(wrapper, element);
|
263
263
|
// If we include the libraries, then we will attempt to run this in shadow dom.
|
264
|
-
|
264
|
+
const useShadowDom = _a.config.includeLibs && (typeof wrapper.attachShadow === 'function');
|
265
|
+
if (useShadowDom) {
|
265
266
|
wrapper = wrapper.attachShadow({
|
266
267
|
mode: 'open'
|
267
268
|
});
|
@@ -269,49 +270,51 @@ class Formio {
|
|
269
270
|
}
|
270
271
|
element.parentNode.removeChild(element);
|
271
272
|
wrapper.appendChild(element);
|
273
|
+
// If this is inside of shadow dom, then we need to add the styles and scripts to the shadow dom.
|
274
|
+
const libWrapper = useShadowDom ? wrapper : document.body;
|
272
275
|
// Load the renderer styles.
|
273
|
-
yield
|
276
|
+
yield _a.addStyles(libWrapper, _a.config.embedCSS || `${_a.cdn.js}/formio.embed.css`);
|
274
277
|
// Add a loader.
|
275
|
-
|
276
|
-
const formioSrc =
|
277
|
-
const renderer =
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
278
|
+
_a.addLoader(wrapper);
|
279
|
+
const formioSrc = _a.config.full ? 'formio.full' : 'formio.form';
|
280
|
+
const renderer = _a.config.debug ? formioSrc : `${formioSrc}.min`;
|
281
|
+
_a.FormioClass = yield _a.addScript(libWrapper, _a.formioScript(_a.config.script || `${_a.cdn.js}/${renderer}.js`, builder), 'Formio', builder ? 'isBuilder' : 'isRenderer');
|
282
|
+
_a.FormioClass.cdn = _a.cdn;
|
283
|
+
_a.FormioClass.setBaseUrl(options.baseUrl || _a.baseUrl || _a.config.base);
|
284
|
+
_a.FormioClass.setProjectUrl(options.projectUrl || _a.projectUrl || _a.config.project);
|
285
|
+
_a.FormioClass.language = _a.language;
|
286
|
+
_a.setLicense(_a.license || _a.config.license || false);
|
287
|
+
_a.modules.forEach((module) => {
|
288
|
+
_a.FormioClass.use(module);
|
286
289
|
});
|
287
|
-
if (
|
288
|
-
|
290
|
+
if (_a.icons) {
|
291
|
+
_a.FormioClass.icons = _a.icons;
|
289
292
|
}
|
290
|
-
if (
|
291
|
-
|
293
|
+
if (_a.pathType) {
|
294
|
+
_a.FormioClass.setPathType(_a.pathType);
|
292
295
|
}
|
293
296
|
// Add libraries if they wish to include the libs.
|
294
|
-
if (
|
295
|
-
yield
|
297
|
+
if (_a.config.template && _a.config.includeLibs) {
|
298
|
+
yield _a.addLibrary(libWrapper, _a.config.libs[_a.config.template], _a.config.template);
|
296
299
|
}
|
297
300
|
// Add the premium modules.
|
298
|
-
if (
|
299
|
-
|
301
|
+
if (_a.config.premium) {
|
302
|
+
_a.config.modules.premium = _a.config.premium;
|
300
303
|
}
|
301
304
|
// Allow adding dynamic modules.
|
302
|
-
if (
|
303
|
-
for (const name in
|
304
|
-
const lib =
|
305
|
+
if (_a.config.modules) {
|
306
|
+
for (const name in _a.config.modules) {
|
307
|
+
const lib = _a.config.modules[name];
|
305
308
|
lib.use = lib.use || true;
|
306
|
-
yield
|
309
|
+
yield _a.addLibrary(libWrapper, lib, name);
|
307
310
|
}
|
308
311
|
}
|
309
|
-
yield
|
310
|
-
if (
|
311
|
-
yield
|
312
|
+
yield _a.addStyles(libWrapper, _a.formioScript(_a.config.style || `${_a.cdn.js}/${renderer}.css`, builder));
|
313
|
+
if (_a.config.before) {
|
314
|
+
yield _a.config.before(_a.FormioClass, element, _a.config);
|
312
315
|
}
|
313
|
-
|
314
|
-
|
316
|
+
_a.FormioClass.license = true;
|
317
|
+
_a._formioReady(_a.FormioClass);
|
315
318
|
return wrapper;
|
316
319
|
});
|
317
320
|
}
|
@@ -322,48 +325,49 @@ class Formio {
|
|
322
325
|
if (loader) {
|
323
326
|
wrapper.removeChild(loader);
|
324
327
|
}
|
325
|
-
|
326
|
-
if (
|
327
|
-
|
328
|
-
|
328
|
+
_a.FormioClass.events.emit(readyEvent, instance);
|
329
|
+
if (_a.config.after) {
|
330
|
+
_a.debug('Calling ready callback');
|
331
|
+
_a.config.after(instance, _a.config);
|
329
332
|
}
|
330
333
|
return instance;
|
331
334
|
});
|
332
335
|
}
|
333
336
|
// Create a new form.
|
334
|
-
static createForm(
|
335
|
-
return __awaiter(this,
|
336
|
-
if (
|
337
|
-
return
|
337
|
+
static createForm(element_1, form_1) {
|
338
|
+
return __awaiter(this, arguments, void 0, function* (element, form, options = {}) {
|
339
|
+
if (_a.FormioClass) {
|
340
|
+
return _a.FormioClass.createForm(element, form, Object.assign(Object.assign({}, options), { noLoader: true }));
|
338
341
|
}
|
339
|
-
const wrapper = yield
|
340
|
-
return
|
342
|
+
const wrapper = yield _a.init(element, options);
|
343
|
+
return _a.FormioClass.createForm(element, form, Object.assign(Object.assign({}, options), { noLoader: true })).then((instance) => {
|
341
344
|
// Set the default submission data.
|
342
|
-
if (
|
343
|
-
|
344
|
-
instance.submission =
|
345
|
+
if (_a.config.submission) {
|
346
|
+
_a.debug('Setting submission', _a.config.submission);
|
347
|
+
instance.submission = _a.config.submission;
|
345
348
|
}
|
346
349
|
// Call the after create method.
|
347
|
-
|
350
|
+
_a.afterCreate(instance, wrapper, 'formEmbedded');
|
348
351
|
return instance;
|
349
352
|
});
|
350
353
|
});
|
351
354
|
}
|
352
355
|
// Create a form builder.
|
353
|
-
static builder(
|
354
|
-
|
355
|
-
|
356
|
-
if ((
|
357
|
-
return
|
356
|
+
static builder(element_1, form_1) {
|
357
|
+
return __awaiter(this, arguments, void 0, function* (element, form, options = {}) {
|
358
|
+
var _a;
|
359
|
+
if ((_a = _a.FormioClass) === null || _a === void 0 ? void 0 : _a.builder) {
|
360
|
+
return _a.FormioClass.builder(element, form, options);
|
358
361
|
}
|
359
|
-
const wrapper = yield
|
360
|
-
return
|
361
|
-
|
362
|
+
const wrapper = yield _a.init(element, options, true);
|
363
|
+
return _a.FormioClass.builder(element, form, options).then((instance) => {
|
364
|
+
_a.afterCreate(instance, wrapper, 'builderEmbedded');
|
362
365
|
return instance;
|
363
366
|
});
|
364
367
|
});
|
365
368
|
}
|
366
369
|
}
|
370
|
+
exports.Formio = Formio;
|
367
371
|
_a = Formio;
|
368
372
|
Formio.FormioClass = null;
|
369
373
|
Formio.config = {};
|
@@ -371,25 +375,24 @@ Formio.modules = [];
|
|
371
375
|
Formio.icons = '';
|
372
376
|
Formio.license = '';
|
373
377
|
Formio.formioReady = new Promise((ready, reject) => {
|
374
|
-
|
375
|
-
|
378
|
+
_a._formioReady = ready;
|
379
|
+
_a._formioReadyReject = reject;
|
376
380
|
});
|
377
381
|
Formio.version = 'FORMIO_VERSION';
|
378
382
|
// Create a report.
|
379
383
|
Formio.Report = {
|
380
|
-
create: (
|
384
|
+
create: (element_1, submission_1, ...args_1) => __awaiter(void 0, [element_1, submission_1, ...args_1], void 0, function* (element, submission, options = {}) {
|
381
385
|
var _b;
|
382
|
-
if ((_b =
|
383
|
-
return
|
386
|
+
if ((_b = _a.FormioClass) === null || _b === void 0 ? void 0 : _b.Report) {
|
387
|
+
return _a.FormioClass.Report.create(element, submission, options);
|
384
388
|
}
|
385
|
-
const wrapper = yield
|
386
|
-
return
|
387
|
-
|
389
|
+
const wrapper = yield _a.init(element, options, true);
|
390
|
+
return _a.FormioClass.Report.create(element, submission, options).then((instance) => {
|
391
|
+
_a.afterCreate(instance, wrapper, 'reportEmbedded');
|
388
392
|
return instance;
|
389
393
|
});
|
390
394
|
})
|
391
395
|
};
|
392
|
-
exports.Formio = Formio;
|
393
396
|
CDN_js_1.default.defaultCDN = Formio.version.includes('rc') ? 'https://cdn.test-form.io' : 'https://cdn.form.io';
|
394
397
|
class Form {
|
395
398
|
constructor(element, form, options) {
|
package/lib/cjs/Webform.js
CHANGED
@@ -214,11 +214,13 @@ class Webform extends NestedDataComponent_1.default {
|
|
214
214
|
this.language = this.i18next.language;
|
215
215
|
// See if we need to restore the draft from a user.
|
216
216
|
if (this.options.saveDraft && !this.options.skipDraftRestore) {
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
217
|
+
this.formReady.then(() => {
|
218
|
+
const user = Formio_1.Formio.getUser();
|
219
|
+
// Only restore a draft if the submission isn't explicitly set.
|
220
|
+
if (user && !this.submissionSet) {
|
221
|
+
this.restoreDraft(user._id);
|
222
|
+
}
|
223
|
+
});
|
222
224
|
}
|
223
225
|
this.component.clearOnHide = false;
|
224
226
|
// Ensure the root is set to this component.
|
@@ -537,6 +539,10 @@ class Webform extends NestedDataComponent_1.default {
|
|
537
539
|
if (form && form.properties) {
|
538
540
|
this.options.properties = form.properties;
|
539
541
|
}
|
542
|
+
// Use the sanitize config from the form settings or the global sanitize config if it is not provided in the options
|
543
|
+
if (!this.options.sanitizeConfig && !this.builderMode) {
|
544
|
+
this.options.sanitizeConfig = lodash_1.default.get(form, 'settings.sanitizeConfig') || lodash_1.default.get(form, 'globalSettings.sanitizeConfig');
|
545
|
+
}
|
540
546
|
if ('schema' in form && (0, compare_versions_1.compareVersions)(form.schema, '1.x') > 0) {
|
541
547
|
this.ready.then(() => {
|
542
548
|
this.setAlert('alert alert-danger', 'Form schema is for a newer version, please upgrade your renderer. Some functionality may not work.');
|
@@ -644,6 +650,11 @@ class Webform extends NestedDataComponent_1.default {
|
|
644
650
|
return this.submissionReadyResolve(submission);
|
645
651
|
}, (err) => this.submissionReadyReject(err)).catch((err) => this.submissionReadyReject(err));
|
646
652
|
}
|
653
|
+
handleDraftError(errName, errDetails, restoreDraft) {
|
654
|
+
const errorMessage = lodash_1.default.trim(`${this.t(errName)} ${errDetails || ''}`);
|
655
|
+
console.warn(errorMessage);
|
656
|
+
this.emit(restoreDraft ? 'restoreDraftError' : 'saveDraftError', errDetails || errorMessage);
|
657
|
+
}
|
647
658
|
/**
|
648
659
|
* Saves a submission draft.
|
649
660
|
*/
|
@@ -652,11 +663,11 @@ class Webform extends NestedDataComponent_1.default {
|
|
652
663
|
return;
|
653
664
|
}
|
654
665
|
if (!this.formio) {
|
655
|
-
|
666
|
+
this.handleDraftError('saveDraftInstanceError');
|
656
667
|
return;
|
657
668
|
}
|
658
669
|
if (!Formio_1.Formio.getUser()) {
|
659
|
-
|
670
|
+
this.handleDraftError('saveDraftAuthError');
|
660
671
|
return;
|
661
672
|
}
|
662
673
|
const draft = (0, utils_1.fastCloneDeep)(this.submission);
|
@@ -669,6 +680,10 @@ class Webform extends NestedDataComponent_1.default {
|
|
669
680
|
this.submission._id = sub._id;
|
670
681
|
this.savingDraft = false;
|
671
682
|
this.emit('saveDraft', sub);
|
683
|
+
})
|
684
|
+
.catch(err => {
|
685
|
+
this.savingDraft = false;
|
686
|
+
this.handleDraftError('saveDraftError', err);
|
672
687
|
});
|
673
688
|
}
|
674
689
|
}
|
@@ -679,7 +694,7 @@ class Webform extends NestedDataComponent_1.default {
|
|
679
694
|
*/
|
680
695
|
restoreDraft(userId) {
|
681
696
|
if (!this.formio) {
|
682
|
-
|
697
|
+
this.handleDraftError('restoreDraftInstanceError', null, true);
|
683
698
|
return;
|
684
699
|
}
|
685
700
|
this.savingDraft = true;
|
@@ -701,6 +716,11 @@ class Webform extends NestedDataComponent_1.default {
|
|
701
716
|
this.draftEnabled = true;
|
702
717
|
this.savingDraft = false;
|
703
718
|
this.emit('restoreDraft', null);
|
719
|
+
})
|
720
|
+
.catch(err => {
|
721
|
+
this.draftEnabled = true;
|
722
|
+
this.savingDraft = false;
|
723
|
+
this.handleDraftError('restoreDraftError', err, true);
|
704
724
|
});
|
705
725
|
}
|
706
726
|
get schema() {
|
@@ -879,7 +899,7 @@ class Webform extends NestedDataComponent_1.default {
|
|
879
899
|
resetValue() {
|
880
900
|
lodash_1.default.each(this.getComponents(), (comp) => (comp.resetValue()));
|
881
901
|
this.setPristine(true);
|
882
|
-
this.onChange();
|
902
|
+
this.onChange({ resetValue: true });
|
883
903
|
}
|
884
904
|
/**
|
885
905
|
* Sets a new alert to display in the error dialog of the form.
|
@@ -985,7 +1005,7 @@ class Webform extends NestedDataComponent_1.default {
|
|
985
1005
|
if (!Array.isArray(errors)) {
|
986
1006
|
errors = [errors];
|
987
1007
|
}
|
988
|
-
errors = errors.concat(this.
|
1008
|
+
errors = errors.concat(this.customErrors);
|
989
1009
|
if (!errors.length) {
|
990
1010
|
this.setAlert(false);
|
991
1011
|
return;
|
@@ -1097,16 +1117,17 @@ class Webform extends NestedDataComponent_1.default {
|
|
1097
1117
|
error = this.normalizeError(error);
|
1098
1118
|
this.submitting = false;
|
1099
1119
|
this.setPristine(false);
|
1100
|
-
this.emit('submitError', error);
|
1120
|
+
this.emit('submitError', error || this.errors);
|
1101
1121
|
// Allow for silent cancellations (no error message, no submit button error state)
|
1102
1122
|
if (error && error.silent) {
|
1103
1123
|
this.emit('change', { isValid: true }, { silent: true });
|
1104
1124
|
return false;
|
1105
1125
|
}
|
1106
|
-
this.showErrors(error, true);
|
1126
|
+
const errors = this.showErrors(error, true);
|
1107
1127
|
if (this.root && this.root.alert) {
|
1108
1128
|
this.scrollIntoView(this.root.alert);
|
1109
1129
|
}
|
1130
|
+
return errors;
|
1110
1131
|
}
|
1111
1132
|
/**
|
1112
1133
|
* Trigger the change event for this form.
|
@@ -1130,7 +1151,9 @@ class Webform extends NestedDataComponent_1.default {
|
|
1130
1151
|
value.isValid = errors.length === 0;
|
1131
1152
|
this.loading = false;
|
1132
1153
|
if (this.submitted) {
|
1133
|
-
|
1154
|
+
// show server errors while they are not cleaned/fixed
|
1155
|
+
const nonComponentServerErrors = lodash_1.default.filter(this.serverErrors || [], err => !err.component && !err.path);
|
1156
|
+
this.showErrors(nonComponentServerErrors.length ? nonComponentServerErrors : null);
|
1134
1157
|
}
|
1135
1158
|
// See if we need to save the draft of the form.
|
1136
1159
|
if (modified && this.options.saveDraft) {
|