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