@formio/js 5.1.0-dev.6056.ba6432d → 5.1.0-dev.6059.845a6e3
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/Changelog.md +13 -131
- package/README.md +1 -28
- package/dist/formio.builder.css +17 -19
- 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 +17 -19
- package/dist/formio.form.js +176 -102
- package/dist/formio.form.min.css +1 -1
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.form.min.js.LICENSE.txt +3 -3
- package/dist/formio.full.css +17 -19
- package/dist/formio.full.js +101 -123
- package/dist/formio.full.min.css +2 -2
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.full.min.js.LICENSE.txt +3 -3
- package/dist/formio.js +10 -10
- package/dist/formio.min.js +1 -1
- package/dist/formio.min.js.LICENSE.txt +1 -1
- package/dist/formio.utils.js +3 -3
- package/dist/formio.utils.min.js +1 -1
- package/dist/formio.utils.min.js.LICENSE.txt +1 -1
- package/lib/cjs/CDN.d.ts +1 -1
- package/lib/cjs/CDN.js +2 -2
- package/lib/cjs/Embed.js +1 -1
- package/lib/cjs/Form.d.ts +6 -4
- package/lib/cjs/Form.js +8 -16
- package/lib/cjs/Formio.js +1 -1
- package/lib/cjs/PDFBuilder.js +4 -4
- package/lib/cjs/Webform.d.ts +13 -16
- package/lib/cjs/Webform.js +148 -162
- package/lib/cjs/WebformBuilder.js +28 -17
- package/lib/cjs/Wizard.js +1 -1
- package/lib/cjs/WizardBuilder.js +2 -15
- package/lib/cjs/components/Components.d.ts +0 -3
- package/lib/cjs/components/_classes/component/Component.d.ts +0 -1
- package/lib/cjs/components/_classes/component/Component.js +11 -38
- package/lib/cjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
- package/lib/cjs/components/_classes/component/editForm/Component.edit.data.d.ts +0 -37
- package/lib/cjs/components/_classes/component/editForm/Component.edit.data.js +2 -13
- package/lib/cjs/components/_classes/component/editForm/utils.d.ts +0 -1
- package/lib/cjs/components/_classes/component/editForm/utils.js +0 -3
- package/lib/cjs/components/_classes/input/Input.js +1 -23
- package/lib/cjs/components/_classes/list/ListComponent.js +4 -4
- package/lib/cjs/components/_classes/multivalue/Multivalue.d.ts +1 -1
- package/lib/cjs/components/_classes/multivalue/Multivalue.js +3 -10
- package/lib/cjs/components/_classes/nested/NestedComponent.form.js +0 -13
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +0 -2
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +31 -52
- package/lib/cjs/components/address/Address.js +1 -1
- package/lib/cjs/components/button/Button.js +6 -6
- package/lib/cjs/components/checkbox/Checkbox.d.ts +1 -1
- package/lib/cjs/components/checkbox/Checkbox.js +2 -2
- package/lib/cjs/components/content/editForm/Content.edit.display.js +0 -8
- package/lib/cjs/components/currency/editForm/Currency.edit.display.js +0 -12
- package/lib/cjs/components/datagrid/DataGrid.d.ts +0 -2
- package/lib/cjs/components/datagrid/DataGrid.js +26 -41
- package/lib/cjs/components/day/Day.js +7 -9
- package/lib/cjs/components/day/editForm/Day.edit.display.js +0 -8
- package/lib/cjs/components/editgrid/EditGrid.d.ts +1 -1
- package/lib/cjs/components/editgrid/EditGrid.js +8 -26
- package/lib/cjs/components/email/editForm/Email.edit.display.js +0 -12
- package/lib/cjs/components/fieldset/editForm/Fieldset.edit.display.js +0 -8
- package/lib/cjs/components/file/File.d.ts +1 -1
- package/lib/cjs/components/file/File.js +17 -23
- package/lib/cjs/components/form/Form.d.ts +1 -1
- package/lib/cjs/components/form/Form.js +5 -9
- package/lib/cjs/components/form/editForm/Form.edit.form.js +3 -3
- package/lib/cjs/components/hidden/Hidden.d.ts +1 -0
- package/lib/cjs/components/hidden/Hidden.js +1 -1
- package/lib/cjs/components/hidden/editForm/Hidden.edit.display.js +0 -8
- package/lib/cjs/components/html/editForm/HTML.edit.display.js +0 -8
- package/lib/cjs/components/number/Number.js +5 -12
- package/lib/cjs/components/number/editForm/Number.edit.display.js +0 -12
- package/lib/cjs/components/password/editForm/Password.edit.display.js +1 -13
- package/lib/cjs/components/phonenumber/PhoneNumber.form.js +1 -9
- package/lib/cjs/components/radio/Radio.js +0 -10
- package/lib/cjs/components/recaptcha/ReCaptcha.js +2 -2
- package/lib/cjs/components/select/Select.d.ts +1 -0
- package/lib/cjs/components/select/Select.js +33 -12
- package/lib/cjs/components/select/editForm/Select.edit.data.d.ts +1 -1
- package/lib/cjs/components/select/editForm/Select.edit.data.js +2 -3
- package/lib/cjs/components/selectboxes/SelectBoxes.js +2 -2
- package/lib/cjs/components/signature/Signature.d.ts +1 -1
- package/lib/cjs/components/signature/Signature.js +3 -5
- package/lib/cjs/components/signature/editForm/Signature.edit.display.d.ts +6 -0
- package/lib/cjs/components/signature/editForm/Signature.edit.display.js +1 -0
- package/lib/cjs/components/survey/Survey.js +2 -2
- package/lib/cjs/components/tabs/editForm/Tabs.edit.display.js +0 -8
- package/lib/cjs/components/tags/Tags.d.ts +1 -1
- package/lib/cjs/components/tags/Tags.js +2 -2
- package/lib/cjs/components/textarea/TextArea.js +6 -6
- package/lib/cjs/components/textarea/editForm/TextArea.edit.display.js +0 -12
- package/lib/cjs/components/url/editForm/Url.edit.display.js +0 -12
- package/lib/cjs/components/well/editForm/Well.edit.display.js +0 -8
- package/lib/cjs/formio.form.js +0 -5
- package/lib/cjs/providers/storage/googleDrive.js +2 -3
- package/lib/cjs/providers/storage/s3.js +3 -3
- package/lib/cjs/providers/storage/xhr.d.ts +0 -1
- package/lib/cjs/providers/storage/xhr.js +1 -6
- package/lib/cjs/translations/en.d.ts +81 -234
- package/lib/cjs/translations/en.js +81 -8
- package/lib/cjs/utils/ChoicesWrapper.d.ts +25 -4
- package/lib/cjs/utils/ChoicesWrapper.js +124 -47
- package/lib/cjs/utils/formUtils.d.ts +2 -2
- package/lib/cjs/utils/i18n.d.ts +2 -5
- package/lib/cjs/utils/i18n.js +5 -32
- package/lib/cjs/widgets/CalendarWidget.js +27 -27
- package/lib/mjs/CDN.d.ts +1 -1
- package/lib/mjs/CDN.js +2 -2
- package/lib/mjs/Embed.js +1 -1
- package/lib/mjs/Form.d.ts +6 -4
- package/lib/mjs/Form.js +9 -17
- package/lib/mjs/Formio.js +1 -1
- package/lib/mjs/PDFBuilder.js +4 -4
- package/lib/mjs/Webform.d.ts +13 -16
- package/lib/mjs/Webform.js +158 -171
- package/lib/mjs/WebformBuilder.js +28 -17
- package/lib/mjs/Wizard.js +1 -1
- package/lib/mjs/WizardBuilder.js +2 -15
- package/lib/mjs/components/Components.d.ts +0 -3
- package/lib/mjs/components/_classes/component/Component.d.ts +0 -1
- package/lib/mjs/components/_classes/component/Component.js +11 -27
- package/lib/mjs/components/_classes/component/editForm/Component.edit.conditional.js +1 -1
- package/lib/mjs/components/_classes/component/editForm/Component.edit.data.d.ts +0 -37
- package/lib/mjs/components/_classes/component/editForm/Component.edit.data.js +2 -13
- package/lib/mjs/components/_classes/component/editForm/utils.d.ts +0 -1
- package/lib/mjs/components/_classes/component/editForm/utils.js +0 -3
- package/lib/mjs/components/_classes/input/Input.js +1 -22
- package/lib/mjs/components/_classes/list/ListComponent.js +4 -4
- package/lib/mjs/components/_classes/multivalue/Multivalue.d.ts +1 -1
- package/lib/mjs/components/_classes/multivalue/Multivalue.js +3 -10
- package/lib/mjs/components/_classes/nested/NestedComponent.form.js +0 -13
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +0 -2
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +31 -53
- package/lib/mjs/components/address/Address.js +1 -1
- package/lib/mjs/components/button/Button.js +6 -6
- package/lib/mjs/components/checkbox/Checkbox.d.ts +1 -1
- package/lib/mjs/components/checkbox/Checkbox.js +2 -2
- package/lib/mjs/components/content/editForm/Content.edit.display.js +0 -8
- package/lib/mjs/components/currency/editForm/Currency.edit.display.js +0 -12
- package/lib/mjs/components/datagrid/DataGrid.d.ts +0 -2
- package/lib/mjs/components/datagrid/DataGrid.js +26 -41
- package/lib/mjs/components/day/Day.js +7 -9
- package/lib/mjs/components/day/editForm/Day.edit.display.js +0 -8
- package/lib/mjs/components/editgrid/EditGrid.d.ts +1 -1
- package/lib/mjs/components/editgrid/EditGrid.js +7 -25
- package/lib/mjs/components/email/editForm/Email.edit.display.js +0 -12
- package/lib/mjs/components/fieldset/editForm/Fieldset.edit.display.js +0 -8
- package/lib/mjs/components/file/File.d.ts +1 -1
- package/lib/mjs/components/file/File.js +17 -23
- package/lib/mjs/components/form/Form.d.ts +1 -1
- package/lib/mjs/components/form/Form.js +5 -8
- package/lib/mjs/components/form/editForm/Form.edit.form.js +3 -3
- package/lib/mjs/components/hidden/Hidden.d.ts +1 -0
- package/lib/mjs/components/hidden/Hidden.js +1 -1
- package/lib/mjs/components/hidden/editForm/Hidden.edit.display.js +0 -8
- package/lib/mjs/components/html/editForm/HTML.edit.display.js +0 -8
- package/lib/mjs/components/number/Number.js +5 -12
- package/lib/mjs/components/number/editForm/Number.edit.display.js +0 -12
- package/lib/mjs/components/password/editForm/Password.edit.display.js +1 -13
- package/lib/mjs/components/phonenumber/PhoneNumber.form.js +1 -9
- package/lib/mjs/components/radio/Radio.js +0 -10
- package/lib/mjs/components/recaptcha/ReCaptcha.js +2 -2
- package/lib/mjs/components/select/Select.d.ts +1 -0
- package/lib/mjs/components/select/Select.js +34 -14
- package/lib/mjs/components/select/editForm/Select.edit.data.d.ts +1 -1
- package/lib/mjs/components/select/editForm/Select.edit.data.js +2 -3
- package/lib/mjs/components/selectboxes/SelectBoxes.js +2 -2
- package/lib/mjs/components/signature/Signature.d.ts +1 -1
- package/lib/mjs/components/signature/Signature.js +3 -5
- package/lib/mjs/components/signature/editForm/Signature.edit.display.d.ts +6 -0
- package/lib/mjs/components/signature/editForm/Signature.edit.display.js +1 -0
- package/lib/mjs/components/survey/Survey.js +2 -2
- package/lib/mjs/components/tabs/editForm/Tabs.edit.display.js +0 -8
- package/lib/mjs/components/tags/Tags.d.ts +1 -1
- package/lib/mjs/components/tags/Tags.js +2 -2
- package/lib/mjs/components/textarea/TextArea.js +6 -6
- package/lib/mjs/components/textarea/editForm/TextArea.edit.display.js +0 -12
- package/lib/mjs/components/url/editForm/Url.edit.display.js +0 -12
- package/lib/mjs/components/well/editForm/Well.edit.display.js +0 -8
- package/lib/mjs/formio.form.js +0 -5
- package/lib/mjs/providers/storage/googleDrive.js +2 -3
- package/lib/mjs/providers/storage/s3.js +3 -3
- package/lib/mjs/providers/storage/xhr.d.ts +0 -1
- package/lib/mjs/providers/storage/xhr.js +1 -6
- package/lib/mjs/translations/en.d.ts +81 -234
- package/lib/mjs/translations/en.js +1 -87
- package/lib/mjs/utils/ChoicesWrapper.d.ts +25 -4
- package/lib/mjs/utils/ChoicesWrapper.js +119 -26
- package/lib/mjs/utils/formUtils.d.ts +2 -2
- package/lib/mjs/utils/i18n.d.ts +2 -5
- package/lib/mjs/utils/i18n.js +5 -32
- package/lib/mjs/widgets/CalendarWidget.js +27 -27
- package/package.json +11 -27
package/lib/mjs/Webform.js
CHANGED
@@ -1,17 +1,18 @@
|
|
1
|
-
import _ from
|
2
|
-
import moment from
|
3
|
-
import { compareVersions } from
|
4
|
-
import EventEmitter from
|
5
|
-
import i18nDefaults from
|
6
|
-
import { Formio } from
|
7
|
-
import Components from
|
8
|
-
import NestedDataComponent from
|
9
|
-
import { fastCloneDeep, currentTimezone, unescapeHTML, getStringFromComponentPath, convertStringToHTMLElement, getArrayFromComponentPath, } from
|
10
|
-
import { eachComponent } from
|
1
|
+
import _ from "lodash";
|
2
|
+
import moment from "moment";
|
3
|
+
import { compareVersions } from "compare-versions";
|
4
|
+
import EventEmitter from "./EventEmitter";
|
5
|
+
import i18nDefaults from "./i18n";
|
6
|
+
import { Formio } from "./Formio";
|
7
|
+
import Components from "./components/Components";
|
8
|
+
import NestedDataComponent from "./components/_classes/nesteddata/NestedDataComponent";
|
9
|
+
import { fastCloneDeep, currentTimezone, unescapeHTML, getStringFromComponentPath, convertStringToHTMLElement, getArrayFromComponentPath, } from "./utils/utils";
|
10
|
+
import { eachComponent } from "./utils/formUtils";
|
11
11
|
// We need this here because dragula pulls in CustomEvent class that requires global to exist.
|
12
12
|
if (typeof window !== 'undefined' && typeof window.global === 'undefined') {
|
13
13
|
window.global = window;
|
14
14
|
}
|
15
|
+
import dragula from "dragula";
|
15
16
|
// Initialize the available forms.
|
16
17
|
Formio.forms = {};
|
17
18
|
// Allow people to register components.
|
@@ -22,10 +23,10 @@ Formio.registerComponent = Components.setComponent;
|
|
22
23
|
* @returns {any} - The icon set.
|
23
24
|
*/
|
24
25
|
function getIconSet(icons) {
|
25
|
-
if (icons ===
|
26
|
-
return
|
26
|
+
if (icons === "fontawesome") {
|
27
|
+
return "fa";
|
27
28
|
}
|
28
|
-
return icons ||
|
29
|
+
return icons || "";
|
29
30
|
}
|
30
31
|
/**
|
31
32
|
*
|
@@ -40,7 +41,7 @@ function getOptions(options) {
|
|
40
41
|
saveDraft: false,
|
41
42
|
alwaysDirty: false,
|
42
43
|
saveDraftThrottle: 5000,
|
43
|
-
display:
|
44
|
+
display: "form",
|
44
45
|
cdnUrl: Formio.cdn.baseUrl,
|
45
46
|
});
|
46
47
|
if (!options.events) {
|
@@ -84,10 +85,10 @@ function getOptions(options) {
|
|
84
85
|
*/
|
85
86
|
/**
|
86
87
|
* @typedef {object} ButtonSettings
|
87
|
-
* @property {boolean} [showPrevious] - Show the
|
88
|
-
* @property {boolean} [showNext] - Show the
|
89
|
-
* @property {boolean} [showCancel] - Show the
|
90
|
-
* @property {boolean} [showSubmit] - Show the
|
88
|
+
* @property {boolean} [showPrevious] - Show the "Previous" button.
|
89
|
+
* @property {boolean} [showNext] - Show the "Next" button.
|
90
|
+
* @property {boolean} [showCancel] - Show the "Cancel" button.
|
91
|
+
* @property {boolean} [showSubmit] - Show the "Submit" button.
|
91
92
|
*/
|
92
93
|
/**
|
93
94
|
* @typedef {object} FormOptions
|
@@ -164,8 +165,8 @@ export default class Webform extends NestedDataComponent {
|
|
164
165
|
* The type of this element.
|
165
166
|
* @type {string}
|
166
167
|
*/
|
167
|
-
this.type =
|
168
|
-
this._src =
|
168
|
+
this.type = "form";
|
169
|
+
this._src = "";
|
169
170
|
this._loading = false;
|
170
171
|
this._form = {};
|
171
172
|
this.draftEnabled = false;
|
@@ -285,26 +286,15 @@ export default class Webform extends NestedDataComponent {
|
|
285
286
|
// Ensure the root is set to this component.
|
286
287
|
this.root = this;
|
287
288
|
this.localRoot = this;
|
289
|
+
this.root.dragulaLib = dragula;
|
288
290
|
}
|
289
291
|
/* eslint-enable max-statements */
|
290
|
-
beforeInit() {
|
291
|
-
this.executeFormController = _.once(this._executeFormController);
|
292
|
-
}
|
293
292
|
get language() {
|
294
293
|
return this.options.language;
|
295
294
|
}
|
296
295
|
get emptyValue() {
|
297
296
|
return null;
|
298
297
|
}
|
299
|
-
get shouldCallFormController() {
|
300
|
-
// If no controller value or
|
301
|
-
// hidden and set to clearOnHide (Don't calculate a value for a hidden field set to clear when hidden)
|
302
|
-
return (this.form &&
|
303
|
-
this.form.controller &&
|
304
|
-
!((!this.visible || this.component.hidden) &&
|
305
|
-
this.component.clearOnHide &&
|
306
|
-
!this.rootPristine));
|
307
|
-
}
|
308
298
|
componentContext() {
|
309
299
|
return this._data;
|
310
300
|
}
|
@@ -325,7 +315,7 @@ export default class Webform extends NestedDataComponent {
|
|
325
315
|
return;
|
326
316
|
}
|
327
317
|
this.rebuild();
|
328
|
-
this.emit(
|
318
|
+
this.emit("languageChanged");
|
329
319
|
});
|
330
320
|
}
|
331
321
|
get componentComponents() {
|
@@ -343,18 +333,18 @@ export default class Webform extends NestedDataComponent {
|
|
343
333
|
addLanguage(code, lang, active = false) {
|
344
334
|
if (this.i18next) {
|
345
335
|
var translations = _.assign(fastCloneDeep(i18nDefaults.resources.en.translation), lang);
|
346
|
-
this.i18next.addResourceBundle(code,
|
336
|
+
this.i18next.addResourceBundle(code, "translation", translations, true, true);
|
347
337
|
if (active) {
|
348
338
|
this.language = code;
|
349
339
|
}
|
350
340
|
}
|
351
341
|
}
|
352
342
|
keyboardCatchableElement(element) {
|
353
|
-
if (element.nodeName ===
|
343
|
+
if (element.nodeName === "TEXTAREA") {
|
354
344
|
return false;
|
355
345
|
}
|
356
|
-
if (element.nodeName ===
|
357
|
-
return [
|
346
|
+
if (element.nodeName === "INPUT") {
|
347
|
+
return ["text", "email", "password"].indexOf(element.type) === -1;
|
358
348
|
}
|
359
349
|
return true;
|
360
350
|
}
|
@@ -365,15 +355,15 @@ export default class Webform extends NestedDataComponent {
|
|
365
355
|
}
|
366
356
|
const ctrl = event.ctrlKey || event.metaKey;
|
367
357
|
const keyCode = event.keyCode;
|
368
|
-
let char =
|
358
|
+
let char = "";
|
369
359
|
if (65 <= keyCode && keyCode <= 90) {
|
370
360
|
char = String.fromCharCode(keyCode);
|
371
361
|
}
|
372
362
|
else if (keyCode === 13) {
|
373
|
-
char =
|
363
|
+
char = "Enter";
|
374
364
|
}
|
375
365
|
else if (keyCode === 27) {
|
376
|
-
char =
|
366
|
+
char = "Esc";
|
377
367
|
}
|
378
368
|
_.each(this.shortcuts, (shortcut) => {
|
379
369
|
if (shortcut.ctrl && !ctrl) {
|
@@ -390,9 +380,9 @@ export default class Webform extends NestedDataComponent {
|
|
390
380
|
return;
|
391
381
|
}
|
392
382
|
shortcut = _.capitalize(shortcut);
|
393
|
-
if (shortcut ===
|
383
|
+
if (shortcut === "Enter" || shortcut === "Esc") {
|
394
384
|
// Restrict Enter and Esc only for buttons
|
395
|
-
if (element.tagName !==
|
385
|
+
if (element.tagName !== "BUTTON") {
|
396
386
|
return;
|
397
387
|
}
|
398
388
|
this.shortcuts.push({
|
@@ -492,13 +482,13 @@ export default class Webform extends NestedDataComponent {
|
|
492
482
|
* @returns {boolean} - TRUE means the url was set, FALSE otherwise.
|
493
483
|
*/
|
494
484
|
setUrl(value, options) {
|
495
|
-
if (!value || typeof value !==
|
485
|
+
if (!value || typeof value !== "string" || value === this._src) {
|
496
486
|
return false;
|
497
487
|
}
|
498
488
|
this._src = value;
|
499
489
|
this.nosubmit = true;
|
500
490
|
this.formio = this.options.formio = new Formio(value, options);
|
501
|
-
if (this.type ===
|
491
|
+
if (this.type === "form") {
|
502
492
|
// Set the options source so this can be passed to other components.
|
503
493
|
this.options.src = value;
|
504
494
|
}
|
@@ -531,17 +521,17 @@ export default class Webform extends NestedDataComponent {
|
|
531
521
|
}
|
532
522
|
/**
|
533
523
|
* Set the loading state for this form, and also show the loader spinner.
|
534
|
-
* @param {boolean} loading - If this form should be
|
524
|
+
* @param {boolean} loading - If this form should be "loading" or not.
|
535
525
|
*/
|
536
526
|
set loading(loading) {
|
537
527
|
if (this._loading !== loading) {
|
538
528
|
this._loading = loading;
|
539
529
|
if (!this.loader && loading) {
|
540
|
-
this.loader = this.ce(
|
541
|
-
class:
|
530
|
+
this.loader = this.ce("div", {
|
531
|
+
class: "loader-wrapper",
|
542
532
|
});
|
543
|
-
const spinner = this.ce(
|
544
|
-
class:
|
533
|
+
const spinner = this.ce("div", {
|
534
|
+
class: "loader text-center",
|
545
535
|
});
|
546
536
|
this.loader.appendChild(spinner);
|
547
537
|
}
|
@@ -625,18 +615,18 @@ export default class Webform extends NestedDataComponent {
|
|
625
615
|
// Use the sanitize config from the form settings or the global sanitize config if it is not provided in the options
|
626
616
|
if (!this.options.sanitizeConfig && !this.builderMode) {
|
627
617
|
this.options.sanitizeConfig =
|
628
|
-
_.get(form,
|
629
|
-
_.get(form,
|
618
|
+
_.get(form, "settings.sanitizeConfig") ||
|
619
|
+
_.get(form, "globalSettings.sanitizeConfig");
|
630
620
|
}
|
631
|
-
if (
|
621
|
+
if ("schema" in form && compareVersions(form.schema, "1.x") > 0) {
|
632
622
|
this.ready.then(() => {
|
633
|
-
this.setAlert(
|
623
|
+
this.setAlert("alert alert-danger", "Form schema is for a newer version, please upgrade your renderer. Some functionality may not work.");
|
634
624
|
});
|
635
625
|
}
|
636
626
|
// See if they pass a module, and evaluate it if so.
|
637
627
|
if (form && form.module) {
|
638
628
|
let formModule = null;
|
639
|
-
if (typeof form.module ===
|
629
|
+
if (typeof form.module === "string") {
|
640
630
|
try {
|
641
631
|
formModule = this.evaluate(`return ${form.module}`);
|
642
632
|
}
|
@@ -658,7 +648,7 @@ export default class Webform extends NestedDataComponent {
|
|
658
648
|
this.initialized = false;
|
659
649
|
const rebuild = this.rebuild() || Promise.resolve();
|
660
650
|
return rebuild.then(() => {
|
661
|
-
this.emit(
|
651
|
+
this.emit("formLoad", form);
|
662
652
|
this.triggerCaptcha();
|
663
653
|
// Make sure to trigger onChange after a render event occurs to speed up form rendering.
|
664
654
|
setTimeout(() => {
|
@@ -732,7 +722,7 @@ export default class Webform extends NestedDataComponent {
|
|
732
722
|
setSubmission(submission, flags = {}) {
|
733
723
|
flags = {
|
734
724
|
...flags,
|
735
|
-
fromSubmission: _.has(flags,
|
725
|
+
fromSubmission: _.has(flags, "fromSubmission") ? flags.fromSubmission : true,
|
736
726
|
};
|
737
727
|
return (this.onSubmission = this.formReady
|
738
728
|
.then((resolveFlags) => {
|
@@ -748,26 +738,26 @@ export default class Webform extends NestedDataComponent {
|
|
748
738
|
.catch((err) => this.submissionReadyReject(err)));
|
749
739
|
}
|
750
740
|
handleDraftError(errName, errDetails, restoreDraft) {
|
751
|
-
const errorMessage = _.trim(`${this.t(errName)} ${errDetails ||
|
741
|
+
const errorMessage = _.trim(`${this.t(errName)} ${errDetails || ""}`);
|
752
742
|
console.warn(errorMessage);
|
753
|
-
this.emit(restoreDraft ?
|
743
|
+
this.emit(restoreDraft ? "restoreDraftError" : "saveDraftError", errDetails || errorMessage);
|
754
744
|
}
|
755
745
|
saveDraft() {
|
756
|
-
if (!this.draftEnabled
|
746
|
+
if (!this.draftEnabled) {
|
757
747
|
return;
|
758
748
|
}
|
759
749
|
if (!this.formio) {
|
760
|
-
this.handleDraftError(
|
750
|
+
this.handleDraftError("saveDraftInstanceError");
|
761
751
|
return;
|
762
752
|
}
|
763
753
|
if (!Formio.getUser()) {
|
764
|
-
this.handleDraftError(
|
754
|
+
this.handleDraftError("saveDraftAuthError");
|
765
755
|
return;
|
766
756
|
}
|
767
757
|
const draft = fastCloneDeep(this.submission);
|
768
|
-
draft.state =
|
758
|
+
draft.state = "draft";
|
769
759
|
if (!this.savingDraft && !this.submitting) {
|
770
|
-
this.emit(
|
760
|
+
this.emit("saveDraftBegin");
|
771
761
|
this.savingDraft = true;
|
772
762
|
this.formio
|
773
763
|
.saveSubmission(draft)
|
@@ -775,11 +765,11 @@ export default class Webform extends NestedDataComponent {
|
|
775
765
|
// Set id to submission to avoid creating new draft submission
|
776
766
|
this.submission._id = sub._id;
|
777
767
|
this.savingDraft = false;
|
778
|
-
this.emit(
|
768
|
+
this.emit("saveDraft", sub);
|
779
769
|
})
|
780
770
|
.catch((err) => {
|
781
771
|
this.savingDraft = false;
|
782
|
-
this.handleDraftError(
|
772
|
+
this.handleDraftError("saveDraftError", err);
|
783
773
|
});
|
784
774
|
}
|
785
775
|
}
|
@@ -790,7 +780,7 @@ export default class Webform extends NestedDataComponent {
|
|
790
780
|
restoreDraft(userId) {
|
791
781
|
const formio = this.formio || this.options.formio;
|
792
782
|
if (!formio) {
|
793
|
-
this.handleDraftError(
|
783
|
+
this.handleDraftError("restoreDraftInstanceError", null, true);
|
794
784
|
return;
|
795
785
|
}
|
796
786
|
this.savingDraft = true;
|
@@ -808,22 +798,22 @@ export default class Webform extends NestedDataComponent {
|
|
808
798
|
return this.setSubmission(draft).then(() => {
|
809
799
|
this.draftEnabled = true;
|
810
800
|
this.savingDraft = false;
|
811
|
-
this.emit(
|
801
|
+
this.emit("restoreDraft", draft);
|
812
802
|
});
|
813
803
|
}
|
814
804
|
// Enable drafts so that we can keep track of changes.
|
815
805
|
this.draftEnabled = true;
|
816
806
|
this.savingDraft = false;
|
817
|
-
this.emit(
|
807
|
+
this.emit("restoreDraft", null);
|
818
808
|
})
|
819
809
|
.catch((err) => {
|
820
810
|
this.draftEnabled = true;
|
821
811
|
this.savingDraft = false;
|
822
|
-
this.handleDraftError(
|
812
|
+
this.handleDraftError("restoreDraftError", err, true);
|
823
813
|
});
|
824
814
|
}
|
825
815
|
get schema() {
|
826
|
-
const schema = fastCloneDeep(_.omit(this._form, [
|
816
|
+
const schema = fastCloneDeep(_.omit(this._form, ["components"]));
|
827
817
|
schema.components = [];
|
828
818
|
this.eachComponent((component) => schema.components.push(component.schema));
|
829
819
|
return schema;
|
@@ -898,28 +888,33 @@ export default class Webform extends NestedDataComponent {
|
|
898
888
|
else {
|
899
889
|
this.component = this.form;
|
900
890
|
}
|
901
|
-
this.component.type =
|
891
|
+
this.component.type = "form";
|
902
892
|
this.component.input = false;
|
903
893
|
this.addComponents();
|
904
|
-
this.on(
|
894
|
+
this.on("submitButton", (options) => {
|
905
895
|
this.submit(false, options).catch((e) => {
|
906
|
-
|
907
|
-
options.instance.loading = false;
|
908
|
-
}
|
896
|
+
options.instance.loading = false;
|
909
897
|
return e !== false && e !== undefined && console.log(e);
|
910
898
|
});
|
911
899
|
}, true);
|
912
|
-
this.on(
|
913
|
-
this.on(
|
914
|
-
this.on(
|
915
|
-
this.on(
|
916
|
-
this.on(
|
917
|
-
|
918
|
-
this.executeFormController();
|
919
|
-
}
|
900
|
+
this.on("checkValidity", (data) => this.validate(data, { dirty: true, process: "change" }), true);
|
901
|
+
this.on("requestUrl", (args) => this.submitUrl(args.url, args.headers), true);
|
902
|
+
this.on("resetForm", () => this.resetValue(), true);
|
903
|
+
this.on("deleteSubmission", () => this.deleteSubmission(), true);
|
904
|
+
this.on("refreshData", () => this.updateValue(), true);
|
905
|
+
this.executeFormController();
|
920
906
|
return this.formReady;
|
921
907
|
}
|
922
|
-
|
908
|
+
executeFormController() {
|
909
|
+
// If no controller value or
|
910
|
+
// hidden and set to clearOnHide (Don't calculate a value for a hidden field set to clear when hidden)
|
911
|
+
if (!this.form ||
|
912
|
+
!this.form.controller ||
|
913
|
+
((!this.visible || this.component.hidden) &&
|
914
|
+
this.component.clearOnHide &&
|
915
|
+
!this.rootPristine)) {
|
916
|
+
return false;
|
917
|
+
}
|
923
918
|
this.formReady.then(() => {
|
924
919
|
this.evaluate(this.form.controller, {
|
925
920
|
components: this.components,
|
@@ -931,19 +926,19 @@ export default class Webform extends NestedDataComponent {
|
|
931
926
|
*
|
932
927
|
*/
|
933
928
|
teardown() {
|
934
|
-
this.emit(
|
929
|
+
this.emit("formDelete", this.id);
|
935
930
|
delete Formio.forms[this.id];
|
936
931
|
delete this.executeShortcuts;
|
937
932
|
delete this.triggerSaveDraft;
|
938
933
|
super.teardown();
|
939
934
|
}
|
940
935
|
destroy(all = false) {
|
941
|
-
this.off(
|
942
|
-
this.off(
|
943
|
-
this.off(
|
944
|
-
this.off(
|
945
|
-
this.off(
|
946
|
-
this.off(
|
936
|
+
this.off("submitButton");
|
937
|
+
this.off("checkValidity");
|
938
|
+
this.off("requestUrl");
|
939
|
+
this.off("resetForm");
|
940
|
+
this.off("deleteSubmission");
|
941
|
+
this.off("refreshData");
|
947
942
|
return super.destroy(all);
|
948
943
|
}
|
949
944
|
build(element) {
|
@@ -956,17 +951,17 @@ export default class Webform extends NestedDataComponent {
|
|
956
951
|
return this.ready;
|
957
952
|
}
|
958
953
|
getClassName() {
|
959
|
-
let classes =
|
954
|
+
let classes = "formio-form";
|
960
955
|
if (this.options.readOnly) {
|
961
|
-
classes +=
|
956
|
+
classes += " formio-read-only";
|
962
957
|
}
|
963
958
|
return classes;
|
964
959
|
}
|
965
960
|
render() {
|
966
|
-
return super.render(this.renderTemplate(
|
961
|
+
return super.render(this.renderTemplate("webform", {
|
967
962
|
classes: this.getClassName(),
|
968
963
|
children: this.renderComponents(),
|
969
|
-
}), this.builderMode ?
|
964
|
+
}), this.builderMode ? "builder" : "form", true);
|
970
965
|
}
|
971
966
|
redraw() {
|
972
967
|
// Don't bother if we have not built yet.
|
@@ -979,13 +974,13 @@ export default class Webform extends NestedDataComponent {
|
|
979
974
|
}
|
980
975
|
attach(element) {
|
981
976
|
this.setElement(element);
|
982
|
-
this.loadRefs(element, { webform:
|
977
|
+
this.loadRefs(element, { webform: "single" });
|
983
978
|
const childPromise = this.attachComponents(this.refs.webform);
|
984
|
-
this.addEventListener(document,
|
979
|
+
this.addEventListener(document, "keydown", this.executeShortcuts);
|
985
980
|
this.currentForm = this;
|
986
|
-
this.hook(
|
981
|
+
this.hook("attachWebform", element, this);
|
987
982
|
return childPromise.then(() => {
|
988
|
-
this.emit(
|
983
|
+
this.emit("render", this.element);
|
989
984
|
return this.setValue(this._submission, {
|
990
985
|
noUpdateEvent: true,
|
991
986
|
});
|
@@ -1008,7 +1003,7 @@ export default class Webform extends NestedDataComponent {
|
|
1008
1003
|
}
|
1009
1004
|
/**
|
1010
1005
|
* Sets a new alert to display in the error dialog of the form.
|
1011
|
-
* @param {string} type - The type of alert to display.
|
1006
|
+
* @param {string} type - The type of alert to display. "danger", "success", "warning", etc.
|
1012
1007
|
* @param {string} message - The message to show in the alert.
|
1013
1008
|
* @param {object} options - The options for the alert.
|
1014
1009
|
*/
|
@@ -1017,8 +1012,8 @@ export default class Webform extends NestedDataComponent {
|
|
1017
1012
|
if (this.alert) {
|
1018
1013
|
if (this.refs.errorRef && this.refs.errorRef.length) {
|
1019
1014
|
this.refs.errorRef.forEach((el) => {
|
1020
|
-
this.removeEventListener(el,
|
1021
|
-
this.removeEventListener(el,
|
1015
|
+
this.removeEventListener(el, "click");
|
1016
|
+
this.removeEventListener(el, "keypress");
|
1022
1017
|
});
|
1023
1018
|
}
|
1024
1019
|
this.removeChild(this.alert);
|
@@ -1028,7 +1023,7 @@ export default class Webform extends NestedDataComponent {
|
|
1028
1023
|
}
|
1029
1024
|
if (this.options.noAlerts) {
|
1030
1025
|
if (!message) {
|
1031
|
-
this.emit(
|
1026
|
+
this.emit("error", false);
|
1032
1027
|
}
|
1033
1028
|
return;
|
1034
1029
|
}
|
@@ -1036,8 +1031,8 @@ export default class Webform extends NestedDataComponent {
|
|
1036
1031
|
try {
|
1037
1032
|
if (this.refs.errorRef && this.refs.errorRef.length) {
|
1038
1033
|
this.refs.errorRef.forEach((el) => {
|
1039
|
-
this.removeEventListener(el,
|
1040
|
-
this.removeEventListener(el,
|
1034
|
+
this.removeEventListener(el, "click");
|
1035
|
+
this.removeEventListener(el, "keypress");
|
1041
1036
|
});
|
1042
1037
|
}
|
1043
1038
|
this.removeChild(this.alert);
|
@@ -1057,19 +1052,19 @@ export default class Webform extends NestedDataComponent {
|
|
1057
1052
|
attrs: attrs,
|
1058
1053
|
type,
|
1059
1054
|
};
|
1060
|
-
this.alert = convertStringToHTMLElement(this.renderTemplate(
|
1055
|
+
this.alert = convertStringToHTMLElement(this.renderTemplate("alert", templateOptions), `#${attrs.id}`);
|
1061
1056
|
}
|
1062
1057
|
if (!this.alert) {
|
1063
1058
|
return;
|
1064
1059
|
}
|
1065
|
-
this.loadRefs(this.alert, { errorRef:
|
1060
|
+
this.loadRefs(this.alert, { errorRef: "multiple" });
|
1066
1061
|
if (this.refs.errorRef && this.refs.errorRef.length) {
|
1067
1062
|
this.refs.errorRef.forEach((el) => {
|
1068
|
-
this.addEventListener(el,
|
1063
|
+
this.addEventListener(el, "click", (e) => {
|
1069
1064
|
const key = e.currentTarget.dataset.componentKey;
|
1070
1065
|
this.focusOnComponent(key);
|
1071
1066
|
});
|
1072
|
-
this.addEventListener(el,
|
1067
|
+
this.addEventListener(el, "keydown", (e) => {
|
1073
1068
|
if (e.keyCode === 13) {
|
1074
1069
|
e.preventDefault();
|
1075
1070
|
const key = e.currentTarget.dataset.componentKey;
|
@@ -1147,8 +1142,8 @@ export default class Webform extends NestedDataComponent {
|
|
1147
1142
|
(err.context?.component && err.context?.component.key) ||
|
1148
1143
|
(err.component && err.component.key) ||
|
1149
1144
|
(err.fromServer && err.path);
|
1150
|
-
const formattedKeyOrPath = keyOrPath ? getStringFromComponentPath(keyOrPath) :
|
1151
|
-
if (typeof err !==
|
1145
|
+
const formattedKeyOrPath = keyOrPath ? getStringFromComponentPath(keyOrPath) : "";
|
1146
|
+
if (typeof err !== "string" && !err.formattedKeyOrPath) {
|
1152
1147
|
err.formattedKeyOrPath = formattedKeyOrPath;
|
1153
1148
|
}
|
1154
1149
|
return {
|
@@ -1158,18 +1153,18 @@ export default class Webform extends NestedDataComponent {
|
|
1158
1153
|
};
|
1159
1154
|
errors.forEach(({ message, context, fromServer, component }, index) => {
|
1160
1155
|
const text = !component?.label || context?.hasLabel || fromServer
|
1161
|
-
? this.t(
|
1162
|
-
: this.t(
|
1156
|
+
? this.t("alertMessage", { message: this.t(message) })
|
1157
|
+
: this.t("alertMessageWithLabel", {
|
1163
1158
|
label: this.t(component?.label),
|
1164
1159
|
message: this.t(message),
|
1165
1160
|
});
|
1166
1161
|
displayedErrors.push(createListItem(text, index));
|
1167
1162
|
});
|
1168
1163
|
}
|
1169
|
-
const errorsList = this.renderTemplate(
|
1170
|
-
this.root.setAlert(
|
1164
|
+
const errorsList = this.renderTemplate("errorsList", { errors: displayedErrors });
|
1165
|
+
this.root.setAlert("danger", errorsList);
|
1171
1166
|
if (triggerEvent) {
|
1172
|
-
this.emit(
|
1167
|
+
this.emit("error", errors);
|
1173
1168
|
}
|
1174
1169
|
return errors;
|
1175
1170
|
}
|
@@ -1189,23 +1184,23 @@ export default class Webform extends NestedDataComponent {
|
|
1189
1184
|
noValidate: true,
|
1190
1185
|
noCheck: true,
|
1191
1186
|
});
|
1192
|
-
this.setAlert(
|
1187
|
+
this.setAlert("success", `<p>${this.t("complete")}</p>`);
|
1193
1188
|
// Cancel triggered saveDraft to prevent overriding the submitted state
|
1194
1189
|
if (this.draftEnabled && this.triggerSaveDraft?.cancel) {
|
1195
1190
|
this.triggerSaveDraft.cancel();
|
1196
1191
|
}
|
1197
|
-
this.emit(
|
1192
|
+
this.emit("submit", submission, saved);
|
1198
1193
|
if (saved) {
|
1199
|
-
this.emit(
|
1194
|
+
this.emit("submitDone", submission);
|
1200
1195
|
}
|
1201
1196
|
return submission;
|
1202
1197
|
}
|
1203
1198
|
normalizeError(error) {
|
1204
1199
|
if (error) {
|
1205
|
-
if (typeof error ===
|
1200
|
+
if (typeof error === "object" && "details" in error) {
|
1206
1201
|
error = error.details;
|
1207
1202
|
}
|
1208
|
-
if (typeof error ===
|
1203
|
+
if (typeof error === "string") {
|
1209
1204
|
error = { message: error };
|
1210
1205
|
}
|
1211
1206
|
}
|
@@ -1220,10 +1215,10 @@ export default class Webform extends NestedDataComponent {
|
|
1220
1215
|
error = this.normalizeError(error);
|
1221
1216
|
this.submitting = false;
|
1222
1217
|
this.setPristine(false);
|
1223
|
-
this.emit(
|
1218
|
+
this.emit("submitError", error || this.errors);
|
1224
1219
|
// Allow for silent cancellations (no error message, no submit button error state)
|
1225
1220
|
if (error && error.silent) {
|
1226
|
-
this.emit(
|
1221
|
+
this.emit("change", { isValid: true }, { silent: true });
|
1227
1222
|
return false;
|
1228
1223
|
}
|
1229
1224
|
const errors = this.showErrors(error, true);
|
@@ -1277,12 +1272,12 @@ export default class Webform extends NestedDataComponent {
|
|
1277
1272
|
this.triggerSaveDraft();
|
1278
1273
|
}
|
1279
1274
|
if (!flags || !flags.noEmit) {
|
1280
|
-
this.emit(
|
1275
|
+
this.emit("change", value, flags, modified);
|
1281
1276
|
isChangeEventEmitted = true;
|
1282
1277
|
}
|
1283
1278
|
// The form is initialized after the first change event occurs.
|
1284
1279
|
if (isChangeEventEmitted && !this.initialized) {
|
1285
|
-
this.emit(
|
1280
|
+
this.emit("initialized");
|
1286
1281
|
this.initialized = true;
|
1287
1282
|
}
|
1288
1283
|
}
|
@@ -1292,7 +1287,7 @@ export default class Webform extends NestedDataComponent {
|
|
1292
1287
|
*/
|
1293
1288
|
deleteSubmission() {
|
1294
1289
|
return this.formio.deleteSubmission().then(() => {
|
1295
|
-
this.emit(
|
1290
|
+
this.emit("submissionDeleted", this.submission);
|
1296
1291
|
this.resetValue();
|
1297
1292
|
});
|
1298
1293
|
}
|
@@ -1303,13 +1298,13 @@ export default class Webform extends NestedDataComponent {
|
|
1303
1298
|
* @returns {boolean} - TRUE means the submission was cancelled, FALSE otherwise.
|
1304
1299
|
*/
|
1305
1300
|
cancel(noconfirm) {
|
1306
|
-
const shouldReset = this.hook(
|
1307
|
-
if (shouldReset && (noconfirm || confirm(this.t(
|
1301
|
+
const shouldReset = this.hook("beforeCancel", true);
|
1302
|
+
if (shouldReset && (noconfirm || confirm(this.t("confirmCancel")))) {
|
1308
1303
|
this.resetValue();
|
1309
1304
|
return true;
|
1310
1305
|
}
|
1311
1306
|
else {
|
1312
|
-
this.emit(
|
1307
|
+
this.emit("cancelSubmit");
|
1313
1308
|
return false;
|
1314
1309
|
}
|
1315
1310
|
}
|
@@ -1317,8 +1312,8 @@ export default class Webform extends NestedDataComponent {
|
|
1317
1312
|
// Add in metadata about client submitting the form
|
1318
1313
|
submission.metadata = submission.metadata || {};
|
1319
1314
|
_.defaults(submission.metadata, {
|
1320
|
-
timezone: _.get(this,
|
1321
|
-
offset: parseInt(_.get(this,
|
1315
|
+
timezone: _.get(this, "_submission.metadata.timezone", currentTimezone()),
|
1316
|
+
offset: parseInt(_.get(this, "_submission.metadata.offset", moment().utcOffset()), 10),
|
1322
1317
|
origin: document.location.origin,
|
1323
1318
|
referrer: document.referrer,
|
1324
1319
|
browserName: navigator.appName,
|
@@ -1339,26 +1334,26 @@ export default class Webform extends NestedDataComponent {
|
|
1339
1334
|
}
|
1340
1335
|
const submission = fastCloneDeep(this.submission || {});
|
1341
1336
|
this.setMetadata(submission);
|
1342
|
-
submission.state = options.state || submission.state ||
|
1343
|
-
const isDraft = submission.state ===
|
1344
|
-
this.hook(
|
1337
|
+
submission.state = options.state || submission.state || "submitted";
|
1338
|
+
const isDraft = submission.state === "draft";
|
1339
|
+
this.hook("beforeSubmit", { ...submission, component: options.component }, (err, data) => {
|
1345
1340
|
if (err) {
|
1346
1341
|
return reject(err);
|
1347
1342
|
}
|
1348
|
-
submission._vnote = data && data._vnote ? data._vnote :
|
1343
|
+
submission._vnote = data && data._vnote ? data._vnote : "";
|
1349
1344
|
try {
|
1350
1345
|
if (!isDraft && !options.noValidate) {
|
1351
1346
|
if (!submission.data) {
|
1352
|
-
return reject(
|
1347
|
+
return reject("Invalid Submission");
|
1353
1348
|
}
|
1354
1349
|
const errors = this.validate(submission.data, {
|
1355
1350
|
local,
|
1356
1351
|
dirty: true,
|
1357
1352
|
silentCheck: false,
|
1358
|
-
process:
|
1353
|
+
process: "submit",
|
1359
1354
|
});
|
1360
1355
|
if (errors.length ||
|
1361
|
-
options.beforeSubmitResults?.some((result) => result.status ===
|
1356
|
+
options.beforeSubmitResults?.some((result) => result.status === "rejected")) {
|
1362
1357
|
return reject(errors);
|
1363
1358
|
}
|
1364
1359
|
}
|
@@ -1367,18 +1362,18 @@ export default class Webform extends NestedDataComponent {
|
|
1367
1362
|
console.error(err);
|
1368
1363
|
}
|
1369
1364
|
this.everyComponent((comp) => {
|
1370
|
-
if (submission._vnote && comp.type ===
|
1365
|
+
if (submission._vnote && comp.type === "form" && comp.component.reference) {
|
1371
1366
|
_.get(submission.data, local ? comp.paths?.localDataPath : comp.path, {})._vnote = submission._vnote;
|
1372
1367
|
}
|
1373
1368
|
const { persistent } = comp.component;
|
1374
|
-
if (persistent ===
|
1369
|
+
if (persistent === "client-only") {
|
1375
1370
|
_.unset(submission.data, local ? comp.paths?.localDataPath : comp.path);
|
1376
1371
|
}
|
1377
1372
|
});
|
1378
|
-
this.hook(
|
1373
|
+
this.hook("customValidation", { ...submission, component: options.component }, (err) => {
|
1379
1374
|
if (err) {
|
1380
1375
|
// If string is returned, cast to object.
|
1381
|
-
if (typeof err ===
|
1376
|
+
if (typeof err === "string") {
|
1382
1377
|
err = {
|
1383
1378
|
message: err,
|
1384
1379
|
};
|
@@ -1392,8 +1387,8 @@ export default class Webform extends NestedDataComponent {
|
|
1392
1387
|
if (this._form && this._form.action) {
|
1393
1388
|
const method = submission.data._id &&
|
1394
1389
|
this._form.action.includes(submission.data._id)
|
1395
|
-
?
|
1396
|
-
:
|
1390
|
+
? "PUT"
|
1391
|
+
: "POST";
|
1397
1392
|
return Formio.makeStaticRequest(this._form.action, method, submission, this.formio ? this.formio.options : {})
|
1398
1393
|
.then((result) => resolve({
|
1399
1394
|
submission: result,
|
@@ -1413,8 +1408,8 @@ export default class Webform extends NestedDataComponent {
|
|
1413
1408
|
}
|
1414
1409
|
// If this is an actionUrl, then make sure to save the action and not the submission.
|
1415
1410
|
const submitMethod = submitFormio.actionUrl
|
1416
|
-
?
|
1417
|
-
:
|
1411
|
+
? "saveAction"
|
1412
|
+
: "saveSubmission";
|
1418
1413
|
submitFormio[submitMethod](submission)
|
1419
1414
|
.then((result) => resolve({
|
1420
1415
|
submission: result,
|
@@ -1431,14 +1426,14 @@ export default class Webform extends NestedDataComponent {
|
|
1431
1426
|
setServerErrors(error) {
|
1432
1427
|
if (error.details) {
|
1433
1428
|
this.serverErrors = error.details
|
1434
|
-
.filter((err) => (err.level ? err.level ===
|
1429
|
+
.filter((err) => (err.level ? err.level === "error" : err))
|
1435
1430
|
.map((err) => {
|
1436
1431
|
err.fromServer = true;
|
1437
1432
|
return err;
|
1438
1433
|
});
|
1439
1434
|
}
|
1440
|
-
else if (typeof error ===
|
1441
|
-
this.serverErrors = [{ fromServer: true, level:
|
1435
|
+
else if (typeof error === "string") {
|
1436
|
+
this.serverErrors = [{ fromServer: true, level: "error", message: error }];
|
1442
1437
|
}
|
1443
1438
|
}
|
1444
1439
|
executeSubmit(options) {
|
@@ -1496,17 +1491,17 @@ export default class Webform extends NestedDataComponent {
|
|
1496
1491
|
}
|
1497
1492
|
submitUrl(URL, headers) {
|
1498
1493
|
if (!URL) {
|
1499
|
-
return console.warn(
|
1494
|
+
return console.warn("Missing URL argument");
|
1500
1495
|
}
|
1501
1496
|
const submission = this.submission || {};
|
1502
1497
|
const API_URL = URL;
|
1503
1498
|
const settings = {
|
1504
|
-
method:
|
1499
|
+
method: "POST",
|
1505
1500
|
headers: {},
|
1506
1501
|
};
|
1507
1502
|
if (headers && headers.length > 0) {
|
1508
1503
|
headers.map((e) => {
|
1509
|
-
if (e.header !==
|
1504
|
+
if (e.header !== "" && e.value !== "") {
|
1510
1505
|
settings.headers[e.header] = this.interpolate(e.value, submission);
|
1511
1506
|
}
|
1512
1507
|
});
|
@@ -1516,26 +1511,25 @@ export default class Webform extends NestedDataComponent {
|
|
1516
1511
|
headers: settings.headers,
|
1517
1512
|
})
|
1518
1513
|
.then(() => {
|
1519
|
-
this.emit(
|
1520
|
-
this.setAlert(
|
1514
|
+
this.emit("requestDone");
|
1515
|
+
this.setAlert("success", "<p> Success </p>");
|
1521
1516
|
})
|
1522
1517
|
.catch((e) => {
|
1523
|
-
const message = `${e.statusText ? e.statusText :
|
1524
|
-
this.emit(
|
1518
|
+
const message = `${e.statusText ? e.statusText : ""} ${e.status ? e.status : e}`;
|
1519
|
+
this.emit("error", message);
|
1525
1520
|
console.error(message);
|
1526
|
-
this.setAlert(
|
1521
|
+
this.setAlert("danger", `<p> ${message} </p>`);
|
1527
1522
|
return Promise.reject(this.onSubmissionError(e));
|
1528
1523
|
});
|
1529
1524
|
}
|
1530
1525
|
else {
|
1531
|
-
|
1532
|
-
this.
|
1533
|
-
|
1534
|
-
return console.warn(message);
|
1526
|
+
this.emit("error", "You should add a URL to this button.");
|
1527
|
+
this.setAlert("warning", "You should add a URL to this button.");
|
1528
|
+
return console.warn("You should add a URL to this button.");
|
1535
1529
|
}
|
1536
1530
|
}
|
1537
1531
|
triggerCaptcha(components = null) {
|
1538
|
-
if (!this || !this.components
|
1532
|
+
if (!this || !this.components) {
|
1539
1533
|
return;
|
1540
1534
|
}
|
1541
1535
|
const captchaComponent = [];
|
@@ -1548,19 +1542,12 @@ export default class Webform extends NestedDataComponent {
|
|
1548
1542
|
if (captchaComponent[0].component.provider === 'google' && components) {
|
1549
1543
|
return;
|
1550
1544
|
}
|
1551
|
-
|
1552
|
-
this.parent.subFormReady.then(() => {
|
1553
|
-
captchaComponent[0].verify(`${this.form.name ? this.form.name : 'form'}Load`);
|
1554
|
-
});
|
1555
|
-
}
|
1556
|
-
else {
|
1557
|
-
captchaComponent[0].verify(`${this.form.name ? this.form.name : 'form'}Load`);
|
1558
|
-
}
|
1545
|
+
captchaComponent[0].verify(`${this.form.name ? this.form.name : 'form'}Load`);
|
1559
1546
|
}
|
1560
1547
|
}
|
1561
1548
|
set nosubmit(value) {
|
1562
1549
|
this._nosubmit = !!value;
|
1563
|
-
this.emit(
|
1550
|
+
this.emit("nosubmit", this._nosubmit);
|
1564
1551
|
}
|
1565
1552
|
get nosubmit() {
|
1566
1553
|
return this._nosubmit || false;
|