@formio/js 5.0.0-dev.5643.9c5173a → 5.0.0-dev.5646.35daa65
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 +65 -2
- package/dist/formio.builder.css +8 -8
- 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 +8 -8
- package/dist/formio.form.js +792 -1237
- 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 -5
- package/dist/formio.full.css +8 -8
- package/dist/formio.full.js +692 -933
- package/dist/formio.full.min.css +1 -1
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.full.min.js.LICENSE.txt +3 -5
- package/dist/formio.js +18 -18
- package/dist/formio.min.js +1 -1
- package/dist/formio.min.js.LICENSE.txt +1 -1
- package/dist/formio.utils.js +1853 -476
- package/dist/formio.utils.min.js +1 -1
- package/dist/formio.utils.min.js.LICENSE.txt +10 -4
- package/embed.d.ts +1 -0
- package/form.d.ts +1 -0
- package/lib/cjs/CDN.d.ts +1 -0
- package/lib/cjs/CDN.js +6 -3
- package/lib/cjs/Element.d.ts +86 -96
- package/lib/cjs/Element.js +68 -78
- package/lib/cjs/Embed.d.ts +1 -1
- package/lib/cjs/Embed.js +52 -12
- package/lib/cjs/Form.d.ts +365 -36
- package/lib/cjs/Form.js +50 -64
- package/lib/cjs/FormBuilder.d.ts +187 -2
- package/lib/cjs/FormBuilder.js +30 -8
- package/lib/cjs/Formio.js +1 -0
- package/lib/cjs/InlineEmbed.d.ts +7 -0
- package/lib/cjs/InlineEmbed.js +116 -0
- package/lib/cjs/PDF.d.ts +11 -13
- package/lib/cjs/PDF.js +6 -8
- package/lib/cjs/Webform.d.ts +187 -139
- package/lib/cjs/Webform.js +330 -300
- package/lib/cjs/WebformBuilder.d.ts +16 -14
- package/lib/cjs/WebformBuilder.js +19 -12
- package/lib/cjs/Wizard.d.ts +31 -21
- package/lib/cjs/Wizard.js +43 -20
- package/lib/cjs/WizardBuilder.d.ts +1 -1
- package/lib/cjs/addons/PasswordStrength/PasswordStrengthAddon.d.ts +8 -5
- package/lib/cjs/addons/PasswordStrength/PasswordStrengthAddon.js +6 -3
- package/lib/cjs/components/Components.d.ts +4 -4
- package/lib/cjs/components/Components.js +3 -3
- package/lib/cjs/components/_classes/component/Component.d.ts +515 -269
- package/lib/cjs/components/_classes/component/Component.form.d.ts +6 -3
- package/lib/cjs/components/_classes/component/Component.form.js +5 -0
- package/lib/cjs/components/_classes/component/Component.js +462 -204
- package/lib/cjs/components/_classes/component/editForm/Component.edit.display.js +1 -1
- package/lib/cjs/components/_classes/component/editForm/Component.edit.validation.js +2 -2
- package/lib/cjs/components/_classes/component/editForm/utils.js +2 -2
- package/lib/cjs/components/_classes/component/fixtures/comp6.d.ts +77 -0
- package/lib/cjs/components/_classes/component/fixtures/comp6.js +59 -0
- package/lib/cjs/components/_classes/component/fixtures/comp7.d.ts +84 -0
- package/lib/cjs/components/_classes/component/fixtures/comp7.js +86 -0
- package/lib/cjs/components/_classes/component/fixtures/index.d.ts +3 -1
- package/lib/cjs/components/_classes/component/fixtures/index.js +5 -1
- package/lib/cjs/components/_classes/field/Field.d.ts +11 -2
- package/lib/cjs/components/_classes/field/Field.js +13 -1
- package/lib/cjs/components/_classes/input/Input.d.ts +4 -3
- package/lib/cjs/components/_classes/input/Input.js +31 -7
- package/lib/cjs/components/_classes/list/ListComponent.d.ts +2 -2
- package/lib/cjs/components/_classes/list/ListComponent.form.d.ts +6 -3
- package/lib/cjs/components/_classes/list/ListComponent.form.js +5 -0
- package/lib/cjs/components/_classes/multivalue/Multivalue.d.ts +43 -12
- package/lib/cjs/components/_classes/multivalue/Multivalue.js +44 -3
- package/lib/cjs/components/_classes/nested/NestedComponent.d.ts +163 -67
- package/lib/cjs/components/_classes/nested/NestedComponent.form.d.ts +6 -3
- package/lib/cjs/components/_classes/nested/NestedComponent.form.js +5 -0
- package/lib/cjs/components/_classes/nested/NestedComponent.js +175 -54
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +2 -2
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
- package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.d.ts +7 -1
- package/lib/cjs/components/_classes/nesteddata/NestedDataComponent.js +2 -3
- package/lib/cjs/components/address/Address.d.ts +4 -2
- package/lib/cjs/components/address/Address.form.d.ts +6 -3
- package/lib/cjs/components/address/Address.form.js +5 -0
- package/lib/cjs/components/address/Address.js +4 -0
- package/lib/cjs/components/address/editForm/Address.edit.provider.js +1 -1
- package/lib/cjs/components/button/Button.d.ts +3 -12
- package/lib/cjs/components/button/Button.form.d.ts +6 -3
- package/lib/cjs/components/button/Button.form.js +5 -0
- package/lib/cjs/components/button/Button.js +5 -0
- package/lib/cjs/components/checkbox/Checkbox.d.ts +5 -28
- package/lib/cjs/components/checkbox/Checkbox.form.d.ts +6 -3
- package/lib/cjs/components/checkbox/Checkbox.form.js +5 -0
- package/lib/cjs/components/checkbox/Checkbox.js +1 -1
- package/lib/cjs/components/checkbox/fixtures/comp6.d.ts +32 -0
- package/lib/cjs/components/checkbox/fixtures/comp6.js +30 -0
- package/lib/cjs/components/checkbox/fixtures/index.d.ts +2 -1
- package/lib/cjs/components/checkbox/fixtures/index.js +3 -1
- package/lib/cjs/components/columns/Columns.d.ts +3 -2
- package/lib/cjs/components/columns/Columns.form.d.ts +6 -3
- package/lib/cjs/components/columns/Columns.form.js +5 -0
- package/lib/cjs/components/columns/Columns.js +1 -1
- package/lib/cjs/components/container/Container.form.d.ts +6 -3
- package/lib/cjs/components/container/Container.form.js +5 -0
- package/lib/cjs/components/content/Content.d.ts +2 -1
- package/lib/cjs/components/content/Content.form.d.ts +6 -3
- package/lib/cjs/components/content/Content.form.js +5 -0
- package/lib/cjs/components/currency/Currency.form.d.ts +6 -3
- package/lib/cjs/components/currency/Currency.form.js +5 -0
- package/lib/cjs/components/currency/Currency.js +1 -2
- package/lib/cjs/components/datagrid/DataGrid.d.ts +17 -7
- package/lib/cjs/components/datagrid/DataGrid.form.d.ts +6 -3
- package/lib/cjs/components/datagrid/DataGrid.form.js +5 -0
- package/lib/cjs/components/datagrid/DataGrid.js +55 -37
- package/lib/cjs/components/datagrid/fixtures/comp-with-reorder.d.ts +100 -0
- package/lib/cjs/components/datagrid/fixtures/comp-with-reorder.js +139 -0
- package/lib/cjs/components/datagrid/fixtures/comp10.d.ts +81 -0
- package/lib/cjs/components/datagrid/fixtures/comp10.js +87 -0
- package/lib/cjs/components/datagrid/fixtures/comp9.d.ts +41 -0
- package/lib/cjs/components/datagrid/fixtures/comp9.js +44 -0
- package/lib/cjs/components/datagrid/fixtures/index.d.ts +4 -1
- package/lib/cjs/components/datagrid/fixtures/index.js +7 -1
- package/lib/cjs/components/datamap/DataMap.d.ts +1 -0
- package/lib/cjs/components/datamap/DataMap.form.d.ts +6 -3
- package/lib/cjs/components/datamap/DataMap.form.js +5 -0
- package/lib/cjs/components/datetime/DateTime.d.ts +0 -14
- package/lib/cjs/components/datetime/DateTime.form.d.ts +6 -3
- package/lib/cjs/components/datetime/DateTime.form.js +5 -0
- package/lib/cjs/components/datetime/editForm/DateTime.edit.date.js +2 -2
- package/lib/cjs/components/day/Day.d.ts +23 -49
- package/lib/cjs/components/day/Day.form.d.ts +6 -3
- package/lib/cjs/components/day/Day.form.js +5 -0
- package/lib/cjs/components/day/Day.js +16 -21
- package/lib/cjs/components/day/fixtures/comp7.d.ts +109 -0
- package/lib/cjs/components/day/fixtures/comp7.js +109 -0
- package/lib/cjs/components/day/fixtures/comp8.d.ts +41 -0
- package/lib/cjs/components/day/fixtures/comp8.js +40 -0
- package/lib/cjs/components/day/fixtures/index.d.ts +3 -1
- package/lib/cjs/components/day/fixtures/index.js +5 -1
- package/lib/cjs/components/editgrid/EditGrid.d.ts +7 -3
- package/lib/cjs/components/editgrid/EditGrid.form.d.ts +6 -3
- package/lib/cjs/components/editgrid/EditGrid.form.js +5 -0
- package/lib/cjs/components/editgrid/EditGrid.js +5 -5
- package/lib/cjs/components/editgrid/editForm/EditGrid.edit.display.js +2 -5
- package/lib/cjs/components/editgrid/editForm/EditGrid.edit.templates.js +6 -9
- package/lib/cjs/components/email/Email.form.d.ts +6 -3
- package/lib/cjs/components/email/Email.form.js +5 -0
- package/lib/cjs/components/fieldset/Fieldset.form.d.ts +6 -3
- package/lib/cjs/components/fieldset/Fieldset.form.js +5 -0
- package/lib/cjs/components/file/File.d.ts +9 -22
- package/lib/cjs/components/file/File.form.d.ts +6 -3
- package/lib/cjs/components/file/File.form.js +5 -0
- package/lib/cjs/components/file/File.js +1 -2
- package/lib/cjs/components/form/Form.d.ts +38 -20
- package/lib/cjs/components/form/Form.form.d.ts +6 -3
- package/lib/cjs/components/form/Form.form.js +5 -0
- package/lib/cjs/components/form/Form.js +27 -15
- package/lib/cjs/components/hidden/Hidden.d.ts +1 -11
- package/lib/cjs/components/hidden/Hidden.form.d.ts +6 -3
- package/lib/cjs/components/hidden/Hidden.form.js +5 -0
- package/lib/cjs/components/hidden/Hidden.js +1 -2
- package/lib/cjs/components/html/HTML.d.ts +2 -1
- package/lib/cjs/components/html/HTML.form.d.ts +6 -3
- package/lib/cjs/components/html/HTML.form.js +5 -0
- package/lib/cjs/components/number/Number.d.ts +3 -17
- package/lib/cjs/components/number/Number.form.d.ts +6 -3
- package/lib/cjs/components/number/Number.form.js +5 -0
- package/lib/cjs/components/number/Number.js +2 -3
- package/lib/cjs/components/number/fixtures/comp8.d.ts +32 -0
- package/lib/cjs/components/number/fixtures/comp8.js +28 -0
- package/lib/cjs/components/number/fixtures/index.d.ts +2 -1
- package/lib/cjs/components/number/fixtures/index.js +3 -1
- package/lib/cjs/components/panel/Panel.form.d.ts +6 -3
- package/lib/cjs/components/panel/Panel.form.js +5 -0
- package/lib/cjs/components/panel/Panel.js +0 -1
- package/lib/cjs/components/password/Password.form.d.ts +6 -3
- package/lib/cjs/components/password/Password.form.js +5 -0
- package/lib/cjs/components/phonenumber/PhoneNumber.form.d.ts +6 -3
- package/lib/cjs/components/phonenumber/PhoneNumber.form.js +5 -0
- package/lib/cjs/components/phonenumber/fixtures/comp2.d.ts +16 -0
- package/lib/cjs/components/phonenumber/fixtures/comp2.js +25 -0
- package/lib/cjs/components/phonenumber/fixtures/index.d.ts +2 -1
- package/lib/cjs/components/phonenumber/fixtures/index.js +3 -1
- package/lib/cjs/components/radio/Radio.d.ts +3 -26
- package/lib/cjs/components/radio/Radio.form.d.ts +6 -3
- package/lib/cjs/components/radio/Radio.form.js +5 -0
- package/lib/cjs/components/radio/Radio.js +6 -7
- package/lib/cjs/components/recaptcha/ReCaptcha.d.ts +1 -1
- package/lib/cjs/components/recaptcha/ReCaptcha.form.d.ts +6 -3
- package/lib/cjs/components/recaptcha/ReCaptcha.form.js +5 -0
- package/lib/cjs/components/select/Select.d.ts +16 -39
- package/lib/cjs/components/select/Select.form.d.ts +6 -3
- package/lib/cjs/components/select/Select.form.js +5 -0
- package/lib/cjs/components/select/Select.js +14 -18
- package/lib/cjs/components/selectboxes/SelectBoxes.d.ts +2 -17
- package/lib/cjs/components/selectboxes/SelectBoxes.form.d.ts +6 -3
- package/lib/cjs/components/selectboxes/SelectBoxes.form.js +5 -0
- package/lib/cjs/components/selectboxes/SelectBoxes.js +7 -9
- package/lib/cjs/components/signature/Signature.d.ts +0 -14
- package/lib/cjs/components/signature/Signature.form.d.ts +6 -3
- package/lib/cjs/components/signature/Signature.form.js +5 -0
- package/lib/cjs/components/signature/Signature.js +1 -1
- package/lib/cjs/components/survey/Survey.d.ts +3 -15
- package/lib/cjs/components/survey/Survey.form.d.ts +6 -3
- package/lib/cjs/components/survey/Survey.form.js +5 -0
- package/lib/cjs/components/table/Table.d.ts +2 -1
- package/lib/cjs/components/table/Table.form.d.ts +6 -3
- package/lib/cjs/components/table/Table.form.js +5 -0
- package/lib/cjs/components/tabs/Tabs.d.ts +4 -4
- package/lib/cjs/components/tabs/Tabs.form.d.ts +6 -3
- package/lib/cjs/components/tabs/Tabs.form.js +5 -0
- package/lib/cjs/components/tabs/Tabs.js +1 -2
- package/lib/cjs/components/tags/Tags.d.ts +0 -14
- package/lib/cjs/components/tags/Tags.form.d.ts +6 -3
- package/lib/cjs/components/tags/Tags.form.js +5 -0
- package/lib/cjs/components/textarea/TextArea.d.ts +4 -9
- package/lib/cjs/components/textarea/TextArea.form.d.ts +6 -3
- package/lib/cjs/components/textarea/TextArea.form.js +5 -0
- package/lib/cjs/components/textarea/TextArea.js +2 -2
- package/lib/cjs/components/textfield/TextField.d.ts +14 -30
- package/lib/cjs/components/textfield/TextField.form.d.ts +6 -3
- package/lib/cjs/components/textfield/TextField.form.js +5 -0
- package/lib/cjs/components/textfield/TextField.js +16 -17
- package/lib/cjs/components/time/Time.form.d.ts +6 -3
- package/lib/cjs/components/time/Time.form.js +5 -0
- package/lib/cjs/components/unknown/Unknown.form.d.ts +5 -34
- package/lib/cjs/components/unknown/Unknown.form.js +4 -0
- package/lib/cjs/components/url/Url.form.d.ts +6 -3
- package/lib/cjs/components/url/Url.form.js +5 -0
- package/lib/cjs/components/well/Well.form.d.ts +6 -3
- package/lib/cjs/components/well/Well.form.js +5 -0
- package/lib/cjs/formio.embed.d.ts +1 -2
- package/lib/cjs/formio.embed.js +2 -100
- package/lib/cjs/formio.form.d.ts +11 -4
- package/lib/cjs/formio.form.js +13 -5
- package/lib/cjs/providers/Providers.d.ts +36 -5
- package/lib/cjs/providers/Providers.js +29 -0
- package/lib/cjs/providers/address/AddressProvider.d.ts +131 -12
- package/lib/cjs/providers/address/AddressProvider.js +88 -2
- package/lib/cjs/providers/address/AzureAddressProvider.d.ts +48 -1
- package/lib/cjs/providers/address/AzureAddressProvider.js +37 -0
- package/lib/cjs/providers/address/CustomAddressProvider.d.ts +27 -4
- package/lib/cjs/providers/address/CustomAddressProvider.js +34 -0
- package/lib/cjs/providers/address/GoogleAddressProvider.d.ts +135 -6
- package/lib/cjs/providers/address/GoogleAddressProvider.js +95 -1
- package/lib/cjs/providers/address/NominatimAddressProvider.d.ts +32 -7
- package/lib/cjs/providers/address/NominatimAddressProvider.js +33 -0
- package/lib/cjs/providers/address/index.d.ts +3 -1
- package/lib/cjs/providers/processor/fileProcessor.d.ts +7 -1
- package/lib/cjs/providers/processor/fileProcessor.js +6 -0
- package/lib/cjs/providers/storage/azure.d.ts +6 -13
- package/lib/cjs/providers/storage/azure.js +5 -0
- package/lib/cjs/providers/storage/base64.d.ts +5 -6
- package/lib/cjs/providers/storage/base64.js +4 -0
- package/lib/cjs/providers/storage/dropbox.d.ts +6 -4
- package/lib/cjs/providers/storage/dropbox.js +5 -0
- package/lib/cjs/providers/storage/googleDrive.d.ts +7 -5
- package/lib/cjs/providers/storage/googleDrive.js +6 -0
- package/lib/cjs/providers/storage/indexeddb.d.ts +5 -7
- package/lib/cjs/providers/storage/indexeddb.js +4 -0
- package/lib/cjs/providers/storage/s3.d.ts +6 -20
- package/lib/cjs/providers/storage/s3.js +5 -0
- package/lib/cjs/providers/storage/url.d.ts +6 -7
- package/lib/cjs/providers/storage/url.js +10 -0
- package/lib/cjs/providers/storage/util.d.ts +24 -1
- package/lib/cjs/providers/storage/util.js +18 -0
- package/lib/cjs/templates/Templates.d.ts +1 -0
- package/lib/cjs/translations/en.d.ts +5 -0
- package/lib/cjs/translations/en.js +6 -1
- package/lib/cjs/utils/ChoicesWrapper.d.ts +1 -1
- package/lib/cjs/utils/ChoicesWrapper.js +13 -2
- package/lib/cjs/utils/Evaluator.d.ts +6 -3
- package/lib/cjs/utils/Evaluator.js +11 -20
- package/lib/cjs/utils/builder.d.ts +9 -7
- package/lib/cjs/utils/builder.js +10 -5
- package/lib/cjs/utils/calendarUtils.d.ts +7 -13
- package/lib/cjs/utils/calendarUtils.js +10 -17
- package/lib/cjs/utils/conditionOperators/IsEmptyValue.js +4 -3
- package/lib/cjs/utils/conditionOperators/IsEqualTo.js +3 -3
- package/lib/cjs/utils/formUtils.d.ts +43 -171
- package/lib/cjs/utils/formUtils.js +38 -569
- package/lib/cjs/utils/utils.d.ts +360 -223
- package/lib/cjs/utils/utils.js +394 -239
- package/lib/cjs/widgets/CalendarWidget.d.ts +9 -10
- package/lib/cjs/widgets/CalendarWidget.js +9 -11
- package/lib/mjs/CDN.d.ts +1 -0
- package/lib/mjs/CDN.js +6 -3
- package/lib/mjs/Element.d.ts +86 -96
- package/lib/mjs/Element.js +68 -78
- package/lib/mjs/Embed.d.ts +1 -1
- package/lib/mjs/Embed.js +52 -12
- package/lib/mjs/Form.d.ts +365 -36
- package/lib/mjs/Form.js +140 -57
- package/lib/mjs/FormBuilder.d.ts +187 -2
- package/lib/mjs/FormBuilder.js +32 -8
- package/lib/mjs/Formio.js +1 -0
- package/lib/mjs/InlineEmbed.d.ts +7 -0
- package/lib/mjs/InlineEmbed.js +112 -0
- package/lib/mjs/PDF.d.ts +11 -13
- package/lib/mjs/PDF.js +6 -8
- package/lib/mjs/Webform.d.ts +187 -139
- package/lib/mjs/Webform.js +342 -312
- package/lib/mjs/WebformBuilder.d.ts +16 -14
- package/lib/mjs/WebformBuilder.js +19 -12
- package/lib/mjs/Wizard.d.ts +31 -21
- package/lib/mjs/Wizard.js +42 -19
- package/lib/mjs/WizardBuilder.d.ts +1 -1
- package/lib/mjs/addons/PasswordStrength/PasswordStrengthAddon.d.ts +8 -5
- package/lib/mjs/addons/PasswordStrength/PasswordStrengthAddon.js +6 -3
- package/lib/mjs/components/Components.d.ts +4 -4
- package/lib/mjs/components/Components.js +3 -3
- package/lib/mjs/components/_classes/component/Component.d.ts +515 -269
- package/lib/mjs/components/_classes/component/Component.form.d.ts +6 -3
- package/lib/mjs/components/_classes/component/Component.form.js +5 -0
- package/lib/mjs/components/_classes/component/Component.js +470 -204
- package/lib/mjs/components/_classes/component/editForm/Component.edit.display.js +1 -1
- package/lib/mjs/components/_classes/component/editForm/Component.edit.validation.js +1 -1
- package/lib/mjs/components/_classes/component/editForm/utils.js +1 -1
- package/lib/mjs/components/_classes/component/fixtures/comp6.d.ts +77 -0
- package/lib/mjs/components/_classes/component/fixtures/comp6.js +57 -0
- package/lib/mjs/components/_classes/component/fixtures/comp7.d.ts +84 -0
- package/lib/mjs/components/_classes/component/fixtures/comp7.js +84 -0
- package/lib/mjs/components/_classes/component/fixtures/index.d.ts +3 -1
- package/lib/mjs/components/_classes/component/fixtures/index.js +3 -1
- package/lib/mjs/components/_classes/field/Field.d.ts +11 -2
- package/lib/mjs/components/_classes/field/Field.js +13 -1
- package/lib/mjs/components/_classes/input/Input.d.ts +4 -3
- package/lib/mjs/components/_classes/input/Input.js +30 -7
- package/lib/mjs/components/_classes/list/ListComponent.d.ts +2 -2
- package/lib/mjs/components/_classes/list/ListComponent.form.d.ts +6 -3
- package/lib/mjs/components/_classes/list/ListComponent.form.js +5 -0
- package/lib/mjs/components/_classes/multivalue/Multivalue.d.ts +43 -12
- package/lib/mjs/components/_classes/multivalue/Multivalue.js +44 -3
- package/lib/mjs/components/_classes/nested/NestedComponent.d.ts +163 -67
- package/lib/mjs/components/_classes/nested/NestedComponent.form.d.ts +6 -3
- package/lib/mjs/components/_classes/nested/NestedComponent.form.js +5 -0
- package/lib/mjs/components/_classes/nested/NestedComponent.js +175 -54
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +2 -2
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +1 -1
- package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.d.ts +7 -1
- package/lib/mjs/components/_classes/nesteddata/NestedDataComponent.js +2 -3
- package/lib/mjs/components/address/Address.d.ts +4 -2
- package/lib/mjs/components/address/Address.form.d.ts +6 -3
- package/lib/mjs/components/address/Address.form.js +5 -0
- package/lib/mjs/components/address/Address.js +4 -0
- package/lib/mjs/components/address/editForm/Address.edit.provider.js +1 -1
- package/lib/mjs/components/button/Button.d.ts +3 -12
- package/lib/mjs/components/button/Button.form.d.ts +6 -3
- package/lib/mjs/components/button/Button.form.js +5 -0
- package/lib/mjs/components/button/Button.js +5 -0
- package/lib/mjs/components/checkbox/Checkbox.d.ts +5 -28
- package/lib/mjs/components/checkbox/Checkbox.form.d.ts +6 -3
- package/lib/mjs/components/checkbox/Checkbox.form.js +5 -0
- package/lib/mjs/components/checkbox/Checkbox.js +1 -1
- package/lib/mjs/components/checkbox/fixtures/comp6.d.ts +32 -0
- package/lib/mjs/components/checkbox/fixtures/comp6.js +28 -0
- package/lib/mjs/components/checkbox/fixtures/index.d.ts +2 -1
- package/lib/mjs/components/checkbox/fixtures/index.js +2 -1
- package/lib/mjs/components/columns/Columns.d.ts +3 -2
- package/lib/mjs/components/columns/Columns.form.d.ts +6 -3
- package/lib/mjs/components/columns/Columns.form.js +5 -0
- package/lib/mjs/components/columns/Columns.js +1 -1
- package/lib/mjs/components/container/Container.form.d.ts +6 -3
- package/lib/mjs/components/container/Container.form.js +5 -0
- package/lib/mjs/components/content/Content.d.ts +2 -1
- package/lib/mjs/components/content/Content.form.d.ts +6 -3
- package/lib/mjs/components/content/Content.form.js +5 -0
- package/lib/mjs/components/currency/Currency.form.d.ts +6 -3
- package/lib/mjs/components/currency/Currency.form.js +5 -0
- package/lib/mjs/components/currency/Currency.js +1 -2
- package/lib/mjs/components/datagrid/DataGrid.d.ts +17 -7
- package/lib/mjs/components/datagrid/DataGrid.form.d.ts +6 -3
- package/lib/mjs/components/datagrid/DataGrid.form.js +5 -0
- package/lib/mjs/components/datagrid/DataGrid.js +55 -37
- package/lib/mjs/components/datagrid/fixtures/comp-with-reorder.d.ts +100 -0
- package/lib/mjs/components/datagrid/fixtures/comp-with-reorder.js +137 -0
- package/lib/mjs/components/datagrid/fixtures/comp10.d.ts +81 -0
- package/lib/mjs/components/datagrid/fixtures/comp10.js +85 -0
- package/lib/mjs/components/datagrid/fixtures/comp9.d.ts +41 -0
- package/lib/mjs/components/datagrid/fixtures/comp9.js +42 -0
- package/lib/mjs/components/datagrid/fixtures/index.d.ts +4 -1
- package/lib/mjs/components/datagrid/fixtures/index.js +4 -1
- package/lib/mjs/components/datamap/DataMap.d.ts +1 -0
- package/lib/mjs/components/datamap/DataMap.form.d.ts +6 -3
- package/lib/mjs/components/datamap/DataMap.form.js +5 -0
- package/lib/mjs/components/datetime/DateTime.d.ts +0 -14
- package/lib/mjs/components/datetime/DateTime.form.d.ts +6 -3
- package/lib/mjs/components/datetime/DateTime.form.js +5 -0
- package/lib/mjs/components/datetime/editForm/DateTime.edit.date.js +1 -1
- package/lib/mjs/components/day/Day.d.ts +23 -49
- package/lib/mjs/components/day/Day.form.d.ts +6 -3
- package/lib/mjs/components/day/Day.form.js +5 -0
- package/lib/mjs/components/day/Day.js +16 -21
- package/lib/mjs/components/day/fixtures/comp7.d.ts +109 -0
- package/lib/mjs/components/day/fixtures/comp7.js +107 -0
- package/lib/mjs/components/day/fixtures/comp8.d.ts +41 -0
- package/lib/mjs/components/day/fixtures/comp8.js +38 -0
- package/lib/mjs/components/day/fixtures/index.d.ts +3 -1
- package/lib/mjs/components/day/fixtures/index.js +3 -1
- package/lib/mjs/components/editgrid/EditGrid.d.ts +7 -3
- package/lib/mjs/components/editgrid/EditGrid.form.d.ts +6 -3
- package/lib/mjs/components/editgrid/EditGrid.form.js +5 -0
- package/lib/mjs/components/editgrid/EditGrid.js +5 -5
- package/lib/mjs/components/editgrid/editForm/EditGrid.edit.display.js +1 -1
- package/lib/mjs/components/editgrid/editForm/EditGrid.edit.templates.js +1 -1
- package/lib/mjs/components/email/Email.form.d.ts +6 -3
- package/lib/mjs/components/email/Email.form.js +5 -0
- package/lib/mjs/components/fieldset/Fieldset.form.d.ts +6 -3
- package/lib/mjs/components/fieldset/Fieldset.form.js +5 -0
- package/lib/mjs/components/file/File.d.ts +9 -22
- package/lib/mjs/components/file/File.form.d.ts +6 -3
- package/lib/mjs/components/file/File.form.js +5 -0
- package/lib/mjs/components/file/File.js +1 -2
- package/lib/mjs/components/form/Form.d.ts +38 -20
- package/lib/mjs/components/form/Form.form.d.ts +6 -3
- package/lib/mjs/components/form/Form.form.js +5 -0
- package/lib/mjs/components/form/Form.js +25 -13
- package/lib/mjs/components/hidden/Hidden.d.ts +1 -11
- package/lib/mjs/components/hidden/Hidden.form.d.ts +6 -3
- package/lib/mjs/components/hidden/Hidden.form.js +5 -0
- package/lib/mjs/components/hidden/Hidden.js +1 -2
- package/lib/mjs/components/html/HTML.d.ts +2 -1
- package/lib/mjs/components/html/HTML.form.d.ts +6 -3
- package/lib/mjs/components/html/HTML.form.js +5 -0
- package/lib/mjs/components/number/Number.d.ts +3 -17
- package/lib/mjs/components/number/Number.form.d.ts +6 -3
- package/lib/mjs/components/number/Number.form.js +5 -0
- package/lib/mjs/components/number/Number.js +2 -3
- package/lib/mjs/components/number/fixtures/comp8.d.ts +32 -0
- package/lib/mjs/components/number/fixtures/comp8.js +26 -0
- package/lib/mjs/components/number/fixtures/index.d.ts +2 -1
- package/lib/mjs/components/number/fixtures/index.js +2 -1
- package/lib/mjs/components/panel/Panel.form.d.ts +6 -3
- package/lib/mjs/components/panel/Panel.form.js +5 -0
- package/lib/mjs/components/panel/Panel.js +0 -1
- package/lib/mjs/components/password/Password.form.d.ts +6 -3
- package/lib/mjs/components/password/Password.form.js +5 -0
- package/lib/mjs/components/phonenumber/PhoneNumber.form.d.ts +6 -3
- package/lib/mjs/components/phonenumber/PhoneNumber.form.js +5 -0
- package/lib/mjs/components/phonenumber/fixtures/comp2.d.ts +16 -0
- package/lib/mjs/components/phonenumber/fixtures/comp2.js +23 -0
- package/lib/mjs/components/phonenumber/fixtures/index.d.ts +2 -1
- package/lib/mjs/components/phonenumber/fixtures/index.js +2 -1
- package/lib/mjs/components/radio/Radio.d.ts +3 -26
- package/lib/mjs/components/radio/Radio.form.d.ts +6 -3
- package/lib/mjs/components/radio/Radio.form.js +5 -0
- package/lib/mjs/components/radio/Radio.js +6 -6
- package/lib/mjs/components/recaptcha/ReCaptcha.d.ts +1 -1
- package/lib/mjs/components/recaptcha/ReCaptcha.form.d.ts +6 -3
- package/lib/mjs/components/recaptcha/ReCaptcha.form.js +5 -0
- package/lib/mjs/components/select/Select.d.ts +16 -39
- package/lib/mjs/components/select/Select.form.d.ts +6 -3
- package/lib/mjs/components/select/Select.form.js +5 -0
- package/lib/mjs/components/select/Select.js +15 -19
- package/lib/mjs/components/selectboxes/SelectBoxes.d.ts +2 -17
- package/lib/mjs/components/selectboxes/SelectBoxes.form.d.ts +6 -3
- package/lib/mjs/components/selectboxes/SelectBoxes.form.js +5 -0
- package/lib/mjs/components/selectboxes/SelectBoxes.js +7 -9
- package/lib/mjs/components/signature/Signature.d.ts +0 -14
- package/lib/mjs/components/signature/Signature.form.d.ts +6 -3
- package/lib/mjs/components/signature/Signature.form.js +5 -0
- package/lib/mjs/components/signature/Signature.js +1 -1
- package/lib/mjs/components/survey/Survey.d.ts +3 -15
- package/lib/mjs/components/survey/Survey.form.d.ts +6 -3
- package/lib/mjs/components/survey/Survey.form.js +5 -0
- package/lib/mjs/components/table/Table.d.ts +2 -1
- package/lib/mjs/components/table/Table.form.d.ts +6 -3
- package/lib/mjs/components/table/Table.form.js +5 -0
- package/lib/mjs/components/tabs/Tabs.d.ts +4 -4
- package/lib/mjs/components/tabs/Tabs.form.d.ts +6 -3
- package/lib/mjs/components/tabs/Tabs.form.js +5 -0
- package/lib/mjs/components/tabs/Tabs.js +1 -2
- package/lib/mjs/components/tags/Tags.d.ts +0 -14
- package/lib/mjs/components/tags/Tags.form.d.ts +6 -3
- package/lib/mjs/components/tags/Tags.form.js +5 -0
- package/lib/mjs/components/textarea/TextArea.d.ts +4 -9
- package/lib/mjs/components/textarea/TextArea.form.d.ts +6 -3
- package/lib/mjs/components/textarea/TextArea.form.js +5 -0
- package/lib/mjs/components/textarea/TextArea.js +2 -2
- package/lib/mjs/components/textfield/TextField.d.ts +14 -30
- package/lib/mjs/components/textfield/TextField.form.d.ts +6 -3
- package/lib/mjs/components/textfield/TextField.form.js +5 -0
- package/lib/mjs/components/textfield/TextField.js +16 -17
- package/lib/mjs/components/time/Time.form.d.ts +6 -3
- package/lib/mjs/components/time/Time.form.js +5 -0
- package/lib/mjs/components/unknown/Unknown.form.d.ts +5 -34
- package/lib/mjs/components/unknown/Unknown.form.js +4 -0
- package/lib/mjs/components/url/Url.form.d.ts +6 -3
- package/lib/mjs/components/url/Url.form.js +5 -0
- package/lib/mjs/components/well/Well.form.d.ts +6 -3
- package/lib/mjs/components/well/Well.form.js +5 -0
- package/lib/mjs/formio.embed.d.ts +1 -2
- package/lib/mjs/formio.embed.js +2 -99
- package/lib/mjs/formio.form.d.ts +11 -4
- package/lib/mjs/formio.form.js +10 -3
- package/lib/mjs/providers/Providers.d.ts +36 -5
- package/lib/mjs/providers/Providers.js +29 -0
- package/lib/mjs/providers/address/AddressProvider.d.ts +131 -12
- package/lib/mjs/providers/address/AddressProvider.js +88 -2
- package/lib/mjs/providers/address/AzureAddressProvider.d.ts +48 -1
- package/lib/mjs/providers/address/AzureAddressProvider.js +37 -0
- package/lib/mjs/providers/address/CustomAddressProvider.d.ts +27 -4
- package/lib/mjs/providers/address/CustomAddressProvider.js +34 -0
- package/lib/mjs/providers/address/GoogleAddressProvider.d.ts +135 -6
- package/lib/mjs/providers/address/GoogleAddressProvider.js +94 -1
- package/lib/mjs/providers/address/NominatimAddressProvider.d.ts +32 -7
- package/lib/mjs/providers/address/NominatimAddressProvider.js +33 -0
- package/lib/mjs/providers/address/index.d.ts +3 -1
- package/lib/mjs/providers/processor/fileProcessor.d.ts +7 -1
- package/lib/mjs/providers/processor/fileProcessor.js +6 -0
- package/lib/mjs/providers/storage/azure.d.ts +6 -13
- package/lib/mjs/providers/storage/azure.js +5 -0
- package/lib/mjs/providers/storage/base64.d.ts +5 -6
- package/lib/mjs/providers/storage/base64.js +4 -0
- package/lib/mjs/providers/storage/dropbox.d.ts +6 -4
- package/lib/mjs/providers/storage/dropbox.js +5 -0
- package/lib/mjs/providers/storage/googleDrive.d.ts +7 -5
- package/lib/mjs/providers/storage/googleDrive.js +6 -0
- package/lib/mjs/providers/storage/indexeddb.d.ts +5 -7
- package/lib/mjs/providers/storage/indexeddb.js +4 -0
- package/lib/mjs/providers/storage/s3.d.ts +6 -20
- package/lib/mjs/providers/storage/s3.js +5 -0
- package/lib/mjs/providers/storage/url.d.ts +6 -7
- package/lib/mjs/providers/storage/url.js +10 -0
- package/lib/mjs/providers/storage/util.d.ts +24 -1
- package/lib/mjs/providers/storage/util.js +18 -0
- package/lib/mjs/templates/Templates.d.ts +1 -0
- package/lib/mjs/translations/en.d.ts +5 -0
- package/lib/mjs/translations/en.js +6 -1
- package/lib/mjs/utils/ChoicesWrapper.d.ts +1 -1
- package/lib/mjs/utils/ChoicesWrapper.js +13 -2
- package/lib/mjs/utils/Evaluator.d.ts +6 -3
- package/lib/mjs/utils/Evaluator.js +9 -20
- package/lib/mjs/utils/builder.d.ts +9 -7
- package/lib/mjs/utils/builder.js +10 -5
- package/lib/mjs/utils/calendarUtils.d.ts +7 -13
- package/lib/mjs/utils/calendarUtils.js +10 -17
- package/lib/mjs/utils/conditionOperators/IsEmptyValue.js +3 -3
- package/lib/mjs/utils/conditionOperators/IsEqualTo.js +1 -1
- package/lib/mjs/utils/formUtils.d.ts +43 -171
- package/lib/mjs/utils/formUtils.js +6 -554
- package/lib/mjs/utils/utils.d.ts +360 -223
- package/lib/mjs/utils/utils.js +387 -233
- package/lib/mjs/widgets/CalendarWidget.d.ts +9 -10
- package/lib/mjs/widgets/CalendarWidget.js +9 -11
- package/package.json +22 -23
- package/sdk.d.ts +1 -0
- package/utils.d.ts +1 -0
package/lib/mjs/Webform.js
CHANGED
|
@@ -1,34 +1,48 @@
|
|
|
1
|
-
import _ from
|
|
2
|
-
import moment from
|
|
3
|
-
import { compareVersions } from
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
|
|
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
|
+
// We need this here because dragula pulls in CustomEvent class that requires global to exist.
|
|
12
|
+
if (typeof window !== 'undefined' && typeof window.global === 'undefined') {
|
|
13
|
+
window.global = window;
|
|
14
|
+
}
|
|
15
|
+
import dragula from "dragula";
|
|
12
16
|
// Initialize the available forms.
|
|
13
17
|
Formio.forms = {};
|
|
14
18
|
// Allow people to register components.
|
|
15
19
|
Formio.registerComponent = Components.setComponent;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {any} icons - The icons to use.
|
|
23
|
+
* @returns {any} - The icon set.
|
|
24
|
+
*/
|
|
16
25
|
function getIconSet(icons) {
|
|
17
|
-
if (icons ===
|
|
18
|
-
return
|
|
26
|
+
if (icons === "fontawesome") {
|
|
27
|
+
return "fa";
|
|
19
28
|
}
|
|
20
|
-
return icons ||
|
|
29
|
+
return icons || "";
|
|
21
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param {any} options - The options to get.
|
|
34
|
+
* @returns {any} - The options.
|
|
35
|
+
*/
|
|
22
36
|
function getOptions(options) {
|
|
23
37
|
options = _.defaults(options, {
|
|
24
38
|
submitOnEnter: false,
|
|
25
|
-
iconset: getIconSet(
|
|
39
|
+
iconset: getIconSet(options && options.icons ? options.icons : Formio.icons),
|
|
26
40
|
i18next: null,
|
|
27
41
|
saveDraft: false,
|
|
28
42
|
alwaysDirty: false,
|
|
29
43
|
saveDraftThrottle: 5000,
|
|
30
|
-
display:
|
|
31
|
-
cdnUrl: Formio.cdn.baseUrl
|
|
44
|
+
display: "form",
|
|
45
|
+
cdnUrl: Formio.cdn.baseUrl,
|
|
32
46
|
});
|
|
33
47
|
if (!options.events) {
|
|
34
48
|
options.events = new EventEmitter();
|
|
@@ -48,36 +62,36 @@ function getOptions(options) {
|
|
|
48
62
|
* @typedef {{[key: string]: JSON}} JSONObject
|
|
49
63
|
*/
|
|
50
64
|
/**
|
|
51
|
-
* @typedef {
|
|
52
|
-
* @property {
|
|
53
|
-
* @property {
|
|
54
|
-
* @property {
|
|
55
|
-
* @property {
|
|
56
|
-
* @property {
|
|
57
|
-
* @property {
|
|
58
|
-
* @property {
|
|
59
|
-
* @property {
|
|
60
|
-
* @property {
|
|
61
|
-
* @property {
|
|
65
|
+
* @typedef {object} FormioHooks
|
|
66
|
+
* @property {Function} [beforeSubmit] - A function that is called before the form is submitted.
|
|
67
|
+
* @property {Function} [beforeCancel] - A function that is called before the form is canceled.
|
|
68
|
+
* @property {Function} [beforeNext] - A function that is called before moving to the next page in a multi-page form.
|
|
69
|
+
* @property {Function} [beforePrev] - A function that is called before moving to the previous page in a multi-page form.
|
|
70
|
+
* @property {Function} [attachComponent] - A function that is called when a component is attached to the form.
|
|
71
|
+
* @property {Function} [setDataValue] - A function that is called when setting the value of a data component.
|
|
72
|
+
* @property {Function} [addComponents] - A function that is called when adding multiple components to the form.
|
|
73
|
+
* @property {Function} [addComponent] - A function that is called when adding a single component to the form.
|
|
74
|
+
* @property {Function} [customValidation] - A function that is called for custom validation of the form.
|
|
75
|
+
* @property {Function} [attachWebform] - A function that is called when attaching a webform to the form.
|
|
62
76
|
*/
|
|
63
77
|
/**
|
|
64
|
-
* @typedef {
|
|
65
|
-
* @property {string[]} [addAttr]
|
|
66
|
-
* @property {string[]} [addTags]
|
|
67
|
-
* @property {string[]} [allowedAttrs]
|
|
68
|
-
* @property {string[]} [allowedTags]
|
|
69
|
-
* @property {string[]} [allowedUriRegex]
|
|
70
|
-
* @property {string[]} [addUriSafeAttr]
|
|
78
|
+
* @typedef {object} SanitizeConfig
|
|
79
|
+
* @property {string[]} [addAttr] - The attributes to add.
|
|
80
|
+
* @property {string[]} [addTags] - The tags to add.
|
|
81
|
+
* @property {string[]} [allowedAttrs] - The allowed attributes.
|
|
82
|
+
* @property {string[]} [allowedTags] - The allowed tags.
|
|
83
|
+
* @property {string[]} [allowedUriRegex] - The allowed URI regex.
|
|
84
|
+
* @property {string[]} [addUriSafeAttr] - The URI safe attributes.
|
|
71
85
|
*/
|
|
72
86
|
/**
|
|
73
|
-
* @typedef {
|
|
74
|
-
* @property {boolean} [showPrevious]
|
|
75
|
-
* @property {boolean} [showNext]
|
|
76
|
-
* @property {boolean} [showCancel]
|
|
77
|
-
* @property {boolean} [showSubmit]
|
|
87
|
+
* @typedef {object} ButtonSettings
|
|
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.
|
|
78
92
|
*/
|
|
79
93
|
/**
|
|
80
|
-
* @typedef {
|
|
94
|
+
* @typedef {object} FormOptions
|
|
81
95
|
* @property {boolean} [saveDraft] - Enable the save draft feature.
|
|
82
96
|
* @property {number} [saveDraftThrottle] - The throttle for the save draft feature.
|
|
83
97
|
* @property {boolean} [readOnly] - Set this form to readOnly.
|
|
@@ -95,7 +109,7 @@ function getOptions(options) {
|
|
|
95
109
|
* @property {string} [componentErrorClass] - The error class for components.
|
|
96
110
|
* @property {any} [templates] - The templates for this form.
|
|
97
111
|
* @property {string} [iconset] - The iconset for this form.
|
|
98
|
-
* @property {Component[]} [components] - The components for this form.
|
|
112
|
+
* @property {import('@formio/core').Component[]} [components] - The components for this form.
|
|
99
113
|
* @property {{[key: string]: boolean}} [disabled] - Disabled components for this form.
|
|
100
114
|
* @property {boolean} [showHiddenFields] - Show hidden fields.
|
|
101
115
|
* @property {{[key: string]: boolean}} [hide] - Hidden components for this form.
|
|
@@ -112,34 +126,32 @@ function getOptions(options) {
|
|
|
112
126
|
* @property {boolean} [sanitize] - Sanitize the form.
|
|
113
127
|
* @property {SanitizeConfig} [sanitizeConfig] - The sanitize configuration for this form.
|
|
114
128
|
* @property {ButtonSettings} [buttonSettings] - The button settings for this form.
|
|
115
|
-
* @property {
|
|
129
|
+
* @property {object} [breadcrumbSettings] - The breadcrumb settings for this form.
|
|
116
130
|
* @property {boolean} [allowPrevious] - Allow the previous button (for Wizard forms).
|
|
117
131
|
* @property {string[]} [wizardButtonOrder] - The order of the buttons (for Wizard forms).
|
|
118
132
|
* @property {boolean} [showCheckboxBackground] - Show the checkbox background.
|
|
133
|
+
* @property {boolean} [inputsOnly] - Only show inputs in the form and no labels.
|
|
134
|
+
* @property {boolean} [building] - If we are in the process of building the form.
|
|
119
135
|
* @property {number} [zoom] - The zoom for PDF forms.
|
|
120
136
|
*/
|
|
121
|
-
/**
|
|
122
|
-
* Renders a Form.io form within the webpage.
|
|
123
|
-
*/
|
|
124
137
|
export default class Webform extends NestedDataComponent {
|
|
125
138
|
/**
|
|
126
|
-
* @type {FormOptions} - the options for this Webform.
|
|
139
|
+
* @type {import('Form').FormOptions} - the options for this Webform.
|
|
127
140
|
*/
|
|
128
141
|
options;
|
|
129
142
|
/**
|
|
130
143
|
* Creates a new Form instance.
|
|
131
|
-
*
|
|
132
|
-
* @param {
|
|
133
|
-
* @param {FormOptions} [options] - The options to create a new form instance.
|
|
144
|
+
* @param {HTMLElement | object | import('Form').FormOptions} [elementOrOptions] - The DOM element to render this form within or the options to create this form instance.
|
|
145
|
+
* @param {import('Form').FormOptions} [options] - The options to create a new form instance.
|
|
134
146
|
*/
|
|
135
|
-
constructor(elementOrOptions, options) {
|
|
147
|
+
constructor(elementOrOptions, options = undefined) {
|
|
136
148
|
let element, formOptions;
|
|
137
149
|
if (elementOrOptions instanceof HTMLElement || options) {
|
|
138
150
|
element = elementOrOptions;
|
|
139
|
-
formOptions = options;
|
|
151
|
+
formOptions = options || {};
|
|
140
152
|
}
|
|
141
153
|
else {
|
|
142
|
-
formOptions = elementOrOptions;
|
|
154
|
+
formOptions = elementOrOptions || {};
|
|
143
155
|
}
|
|
144
156
|
super(null, getOptions(formOptions));
|
|
145
157
|
this.setElement(element);
|
|
@@ -153,12 +165,12 @@ export default class Webform extends NestedDataComponent {
|
|
|
153
165
|
* The type of this element.
|
|
154
166
|
* @type {string}
|
|
155
167
|
*/
|
|
156
|
-
this.type =
|
|
157
|
-
this._src =
|
|
168
|
+
this.type = "form";
|
|
169
|
+
this._src = "";
|
|
158
170
|
this._loading = false;
|
|
159
171
|
this._form = {};
|
|
160
172
|
this.draftEnabled = false;
|
|
161
|
-
this.savingDraft =
|
|
173
|
+
this.savingDraft = false;
|
|
162
174
|
if (this.options.saveDraftThrottle) {
|
|
163
175
|
this.triggerSaveDraft = _.throttle(this.saveDraft.bind(this), this.options.saveDraftThrottle);
|
|
164
176
|
}
|
|
@@ -172,13 +184,11 @@ export default class Webform extends NestedDataComponent {
|
|
|
172
184
|
this.nosubmit = false;
|
|
173
185
|
/**
|
|
174
186
|
* Determines if the form has tried to be submitted, error or not.
|
|
175
|
-
*
|
|
176
187
|
* @type {boolean}
|
|
177
188
|
*/
|
|
178
189
|
this.submitted = false;
|
|
179
190
|
/**
|
|
180
191
|
* Determines if the form is being submitted at the moment.
|
|
181
|
-
*
|
|
182
192
|
* @type {boolean}
|
|
183
193
|
*/
|
|
184
194
|
this.submitting = false;
|
|
@@ -210,7 +220,6 @@ export default class Webform extends NestedDataComponent {
|
|
|
210
220
|
/**
|
|
211
221
|
* Promise that executes when the form is ready and rendered.
|
|
212
222
|
* @type {Promise}
|
|
213
|
-
*
|
|
214
223
|
* @example
|
|
215
224
|
* import Webform from '@formio/js/Webform';
|
|
216
225
|
* let form = new Webform(document.getElementById('formio'));
|
|
@@ -222,21 +231,18 @@ export default class Webform extends NestedDataComponent {
|
|
|
222
231
|
this.formReady = new Promise((resolve, reject) => {
|
|
223
232
|
/**
|
|
224
233
|
* Called when the formReady state of this form has been resolved.
|
|
225
|
-
*
|
|
226
|
-
* @type {function}
|
|
234
|
+
* @type {Function}
|
|
227
235
|
*/
|
|
228
236
|
this.formReadyResolve = resolve;
|
|
229
237
|
/**
|
|
230
238
|
* Called when this form could not load and is rejected.
|
|
231
|
-
*
|
|
232
|
-
* @type {function}
|
|
239
|
+
* @type {Function}
|
|
233
240
|
*/
|
|
234
241
|
this.formReadyReject = reject;
|
|
235
242
|
});
|
|
236
243
|
/**
|
|
237
244
|
* Promise that executes when the submission is ready and rendered.
|
|
238
245
|
* @type {Promise}
|
|
239
|
-
*
|
|
240
246
|
* @example
|
|
241
247
|
* import Webform from '@formio/js/Webform';
|
|
242
248
|
* let form = new Webform(document.getElementById('formio'));
|
|
@@ -248,14 +254,12 @@ export default class Webform extends NestedDataComponent {
|
|
|
248
254
|
this.submissionReady = new Promise((resolve, reject) => {
|
|
249
255
|
/**
|
|
250
256
|
* Called when the formReady state of this form has been resolved.
|
|
251
|
-
*
|
|
252
|
-
* @type {function}
|
|
257
|
+
* @type {Function}
|
|
253
258
|
*/
|
|
254
259
|
this.submissionReadyResolve = resolve;
|
|
255
260
|
/**
|
|
256
261
|
* Called when this form could not load and is rejected.
|
|
257
|
-
*
|
|
258
|
-
* @type {function}
|
|
262
|
+
* @type {Function}
|
|
259
263
|
*/
|
|
260
264
|
this.submissionReadyReject = reject;
|
|
261
265
|
});
|
|
@@ -264,25 +268,25 @@ export default class Webform extends NestedDataComponent {
|
|
|
264
268
|
this.language = this.i18next.language;
|
|
265
269
|
// See if we need to restore the draft from a user.
|
|
266
270
|
if (this.options.saveDraft) {
|
|
267
|
-
this.
|
|
268
|
-
|
|
271
|
+
if (this.options.skipDraftRestore) {
|
|
272
|
+
this.draftEnabled = true;
|
|
273
|
+
this.savingDraft = false;
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
this.formReady.then(() => {
|
|
269
277
|
const user = Formio.getUser();
|
|
270
278
|
// Only restore a draft if the submission isn't explicitly set.
|
|
271
279
|
if (user && !this.submissionSet) {
|
|
272
280
|
this.restoreDraft(user._id);
|
|
273
281
|
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// Enable drafts
|
|
277
|
-
this.draftEnabled = true;
|
|
278
|
-
this.savingDraft = false;
|
|
279
|
-
}
|
|
280
|
-
});
|
|
282
|
+
});
|
|
283
|
+
}
|
|
281
284
|
}
|
|
282
285
|
this.component.clearOnHide = false;
|
|
283
286
|
// Ensure the root is set to this component.
|
|
284
287
|
this.root = this;
|
|
285
288
|
this.localRoot = this;
|
|
289
|
+
this.root.dragulaLib = dragula;
|
|
286
290
|
}
|
|
287
291
|
/* eslint-enable max-statements */
|
|
288
292
|
get language() {
|
|
@@ -296,9 +300,7 @@ export default class Webform extends NestedDataComponent {
|
|
|
296
300
|
}
|
|
297
301
|
/**
|
|
298
302
|
* Sets the language for this form.
|
|
299
|
-
*
|
|
300
|
-
* @param lang
|
|
301
|
-
* @return {Promise}
|
|
303
|
+
* @param {string} lang - The language to use (e.g. 'en', 'sp', etc.)
|
|
302
304
|
*/
|
|
303
305
|
set language(lang) {
|
|
304
306
|
if (!this.i18next) {
|
|
@@ -313,7 +315,7 @@ export default class Webform extends NestedDataComponent {
|
|
|
313
315
|
return;
|
|
314
316
|
}
|
|
315
317
|
this.rebuild();
|
|
316
|
-
this.emit(
|
|
318
|
+
this.emit("languageChanged");
|
|
317
319
|
});
|
|
318
320
|
}
|
|
319
321
|
get componentComponents() {
|
|
@@ -324,31 +326,25 @@ export default class Webform extends NestedDataComponent {
|
|
|
324
326
|
}
|
|
325
327
|
/**
|
|
326
328
|
* Add a language for translations
|
|
327
|
-
*
|
|
328
|
-
* @param
|
|
329
|
-
* @param
|
|
330
|
-
* @param active
|
|
331
|
-
* @return {*}
|
|
329
|
+
* @param {string} code - The language code for the language being added.
|
|
330
|
+
* @param {object} lang - The language translations.
|
|
331
|
+
* @param {boolean} [active] - If this language should be set as the active language.
|
|
332
332
|
*/
|
|
333
333
|
addLanguage(code, lang, active = false) {
|
|
334
334
|
if (this.i18next) {
|
|
335
335
|
var translations = _.assign(fastCloneDeep(i18nDefaults.resources.en.translation), lang);
|
|
336
|
-
this.i18next.addResourceBundle(code,
|
|
336
|
+
this.i18next.addResourceBundle(code, "translation", translations, true, true);
|
|
337
337
|
if (active) {
|
|
338
338
|
this.language = code;
|
|
339
339
|
}
|
|
340
340
|
}
|
|
341
341
|
}
|
|
342
342
|
keyboardCatchableElement(element) {
|
|
343
|
-
if (element.nodeName ===
|
|
343
|
+
if (element.nodeName === "TEXTAREA") {
|
|
344
344
|
return false;
|
|
345
345
|
}
|
|
346
|
-
if (element.nodeName ===
|
|
347
|
-
return [
|
|
348
|
-
'text',
|
|
349
|
-
'email',
|
|
350
|
-
'password'
|
|
351
|
-
].indexOf(element.type) === -1;
|
|
346
|
+
if (element.nodeName === "INPUT") {
|
|
347
|
+
return ["text", "email", "password"].indexOf(element.type) === -1;
|
|
352
348
|
}
|
|
353
349
|
return true;
|
|
354
350
|
}
|
|
@@ -359,15 +355,15 @@ export default class Webform extends NestedDataComponent {
|
|
|
359
355
|
}
|
|
360
356
|
const ctrl = event.ctrlKey || event.metaKey;
|
|
361
357
|
const keyCode = event.keyCode;
|
|
362
|
-
let char =
|
|
358
|
+
let char = "";
|
|
363
359
|
if (65 <= keyCode && keyCode <= 90) {
|
|
364
360
|
char = String.fromCharCode(keyCode);
|
|
365
361
|
}
|
|
366
362
|
else if (keyCode === 13) {
|
|
367
|
-
char =
|
|
363
|
+
char = "Enter";
|
|
368
364
|
}
|
|
369
365
|
else if (keyCode === 27) {
|
|
370
|
-
char =
|
|
366
|
+
char = "Esc";
|
|
371
367
|
}
|
|
372
368
|
_.each(this.shortcuts, (shortcut) => {
|
|
373
369
|
if (shortcut.ctrl && !ctrl) {
|
|
@@ -384,21 +380,21 @@ export default class Webform extends NestedDataComponent {
|
|
|
384
380
|
return;
|
|
385
381
|
}
|
|
386
382
|
shortcut = _.capitalize(shortcut);
|
|
387
|
-
if (shortcut ===
|
|
383
|
+
if (shortcut === "Enter" || shortcut === "Esc") {
|
|
388
384
|
// Restrict Enter and Esc only for buttons
|
|
389
|
-
if (element.tagName !==
|
|
385
|
+
if (element.tagName !== "BUTTON") {
|
|
390
386
|
return;
|
|
391
387
|
}
|
|
392
388
|
this.shortcuts.push({
|
|
393
389
|
shortcut,
|
|
394
|
-
element
|
|
390
|
+
element,
|
|
395
391
|
});
|
|
396
392
|
}
|
|
397
393
|
else {
|
|
398
394
|
this.shortcuts.push({
|
|
399
395
|
ctrl: true,
|
|
400
396
|
shortcut,
|
|
401
|
-
element
|
|
397
|
+
element,
|
|
402
398
|
});
|
|
403
399
|
}
|
|
404
400
|
}
|
|
@@ -408,24 +404,27 @@ export default class Webform extends NestedDataComponent {
|
|
|
408
404
|
}
|
|
409
405
|
_.remove(this.shortcuts, {
|
|
410
406
|
shortcut,
|
|
411
|
-
element
|
|
407
|
+
element,
|
|
412
408
|
});
|
|
413
409
|
}
|
|
414
410
|
/**
|
|
415
411
|
* Get the embed source of the form.
|
|
416
|
-
*
|
|
417
|
-
* @returns {string}
|
|
412
|
+
* @returns {string} - The source of the form.
|
|
418
413
|
*/
|
|
419
414
|
get src() {
|
|
420
415
|
return this._src;
|
|
421
416
|
}
|
|
422
417
|
/**
|
|
423
418
|
* Loads the submission if applicable.
|
|
419
|
+
* @returns {Promise} - The promise that is triggered when the submission is loaded.
|
|
424
420
|
*/
|
|
425
421
|
loadSubmission() {
|
|
426
422
|
this.loadingSubmission = true;
|
|
427
423
|
if (this.formio.submissionId) {
|
|
428
|
-
this.onSubmission = this.formio
|
|
424
|
+
this.onSubmission = this.formio
|
|
425
|
+
.loadSubmission()
|
|
426
|
+
.then((submission) => this.setSubmission(submission), (err) => this.submissionReadyReject(err))
|
|
427
|
+
.catch((err) => this.submissionReadyReject(err));
|
|
429
428
|
}
|
|
430
429
|
else {
|
|
431
430
|
this.submissionReadyResolve();
|
|
@@ -434,18 +433,21 @@ export default class Webform extends NestedDataComponent {
|
|
|
434
433
|
}
|
|
435
434
|
/**
|
|
436
435
|
* Set the src of the form renderer.
|
|
437
|
-
*
|
|
438
|
-
* @param
|
|
439
|
-
* @
|
|
436
|
+
* @param {string} value - The source value to set.
|
|
437
|
+
* @param {any} options - The options to set.
|
|
438
|
+
* @returns {Promise} - The promise that is triggered when the form is set.
|
|
440
439
|
*/
|
|
441
440
|
setSrc(value, options) {
|
|
442
441
|
if (this.setUrl(value, options)) {
|
|
443
442
|
this.nosubmit = false;
|
|
444
|
-
return this.formio
|
|
443
|
+
return this.formio
|
|
444
|
+
.loadForm({ params: { live: 1 } })
|
|
445
|
+
.then((form) => {
|
|
445
446
|
const setForm = this.setForm(form);
|
|
446
447
|
this.loadSubmission();
|
|
447
448
|
return setForm;
|
|
448
|
-
})
|
|
449
|
+
})
|
|
450
|
+
.catch((err) => {
|
|
449
451
|
console.warn(err);
|
|
450
452
|
this.formReadyReject(err);
|
|
451
453
|
});
|
|
@@ -454,9 +456,7 @@ export default class Webform extends NestedDataComponent {
|
|
|
454
456
|
}
|
|
455
457
|
/**
|
|
456
458
|
* Set the Form source, which is typically the Form.io embed URL.
|
|
457
|
-
*
|
|
458
459
|
* @param {string} value - The value of the form embed url.
|
|
459
|
-
*
|
|
460
460
|
* @example
|
|
461
461
|
* import Webform from '@formio/js/Webform';
|
|
462
462
|
* let form = new Webform(document.getElementById('formio'));
|
|
@@ -470,28 +470,25 @@ export default class Webform extends NestedDataComponent {
|
|
|
470
470
|
}
|
|
471
471
|
/**
|
|
472
472
|
* Get the embed source of the form.
|
|
473
|
-
*
|
|
474
|
-
* @returns {string}
|
|
473
|
+
* @returns {string} - returns the source of the form.
|
|
475
474
|
*/
|
|
476
475
|
get url() {
|
|
477
476
|
return this._src;
|
|
478
477
|
}
|
|
479
478
|
/**
|
|
480
479
|
* Sets the url of the form renderer.
|
|
481
|
-
*
|
|
482
|
-
* @param
|
|
483
|
-
* @
|
|
480
|
+
* @param {string} value - The value to set the url to.
|
|
481
|
+
* @param {any} options - The options to set.
|
|
482
|
+
* @returns {boolean} - TRUE means the url was set, FALSE otherwise.
|
|
484
483
|
*/
|
|
485
484
|
setUrl(value, options) {
|
|
486
|
-
if (!value ||
|
|
487
|
-
(typeof value !== 'string') ||
|
|
488
|
-
(value === this._src)) {
|
|
485
|
+
if (!value || typeof value !== "string" || value === this._src) {
|
|
489
486
|
return false;
|
|
490
487
|
}
|
|
491
488
|
this._src = value;
|
|
492
489
|
this.nosubmit = true;
|
|
493
490
|
this.formio = this.options.formio = new Formio(value, options);
|
|
494
|
-
if (this.type ===
|
|
491
|
+
if (this.type === "form") {
|
|
495
492
|
// Set the options source so this can be passed to other components.
|
|
496
493
|
this.options.src = value;
|
|
497
494
|
}
|
|
@@ -499,7 +496,6 @@ export default class Webform extends NestedDataComponent {
|
|
|
499
496
|
}
|
|
500
497
|
/**
|
|
501
498
|
* Set the form source but don't initialize the form and submission from the url.
|
|
502
|
-
*
|
|
503
499
|
* @param {string} value - The value of the form embed url.
|
|
504
500
|
*/
|
|
505
501
|
set url(value) {
|
|
@@ -507,7 +503,6 @@ export default class Webform extends NestedDataComponent {
|
|
|
507
503
|
}
|
|
508
504
|
/**
|
|
509
505
|
* Called when both the form and submission have been loaded.
|
|
510
|
-
*
|
|
511
506
|
* @returns {Promise} - The promise to trigger when both form and submission have loaded.
|
|
512
507
|
*/
|
|
513
508
|
get ready() {
|
|
@@ -519,7 +514,6 @@ export default class Webform extends NestedDataComponent {
|
|
|
519
514
|
}
|
|
520
515
|
/**
|
|
521
516
|
* Returns if this form is loading.
|
|
522
|
-
*
|
|
523
517
|
* @returns {boolean} - TRUE means the form is loading, FALSE otherwise.
|
|
524
518
|
*/
|
|
525
519
|
get loading() {
|
|
@@ -527,18 +521,17 @@ export default class Webform extends NestedDataComponent {
|
|
|
527
521
|
}
|
|
528
522
|
/**
|
|
529
523
|
* Set the loading state for this form, and also show the loader spinner.
|
|
530
|
-
*
|
|
531
524
|
* @param {boolean} loading - If this form should be "loading" or not.
|
|
532
525
|
*/
|
|
533
526
|
set loading(loading) {
|
|
534
527
|
if (this._loading !== loading) {
|
|
535
528
|
this._loading = loading;
|
|
536
529
|
if (!this.loader && loading) {
|
|
537
|
-
this.loader = this.ce(
|
|
538
|
-
class:
|
|
530
|
+
this.loader = this.ce("div", {
|
|
531
|
+
class: "loader-wrapper",
|
|
539
532
|
});
|
|
540
|
-
const spinner = this.ce(
|
|
541
|
-
class:
|
|
533
|
+
const spinner = this.ce("div", {
|
|
534
|
+
class: "loader text-center",
|
|
542
535
|
});
|
|
543
536
|
this.loader.appendChild(spinner);
|
|
544
537
|
}
|
|
@@ -561,7 +554,6 @@ export default class Webform extends NestedDataComponent {
|
|
|
561
554
|
}
|
|
562
555
|
/**
|
|
563
556
|
* Sets the JSON schema for the form to be rendered.
|
|
564
|
-
*
|
|
565
557
|
* @example
|
|
566
558
|
* import Webform from '@formio/js/Webform';
|
|
567
559
|
* let form = new Webform(document.getElementById('formio'));
|
|
@@ -589,12 +581,11 @@ export default class Webform extends NestedDataComponent {
|
|
|
589
581
|
* }
|
|
590
582
|
* ]
|
|
591
583
|
* });
|
|
592
|
-
*
|
|
593
|
-
* @param {
|
|
594
|
-
* @
|
|
595
|
-
* @returns {*}
|
|
584
|
+
* @param {object} form - The JSON schema of the form @see https://examples.form.io/example for an example JSON schema.
|
|
585
|
+
* @param {any} flags - Any flags to apply when setting the form.
|
|
586
|
+
* @returns {Promise} - The promise that is triggered when the form is set.
|
|
596
587
|
*/
|
|
597
|
-
setForm(form, flags) {
|
|
588
|
+
setForm(form, flags = {}) {
|
|
598
589
|
const isFormAlreadySet = this._form && this._form.components?.length;
|
|
599
590
|
try {
|
|
600
591
|
// Do not set the form again if it has been already set
|
|
@@ -624,17 +615,19 @@ export default class Webform extends NestedDataComponent {
|
|
|
624
615
|
}
|
|
625
616
|
// Use the sanitize config from the form settings or the global sanitize config if it is not provided in the options
|
|
626
617
|
if (!this.options.sanitizeConfig && !this.builderMode) {
|
|
627
|
-
this.options.sanitizeConfig =
|
|
618
|
+
this.options.sanitizeConfig =
|
|
619
|
+
_.get(form, "settings.sanitizeConfig") ||
|
|
620
|
+
_.get(form, "globalSettings.sanitizeConfig");
|
|
628
621
|
}
|
|
629
|
-
if (
|
|
622
|
+
if ("schema" in form && compareVersions(form.schema, "1.x") > 0) {
|
|
630
623
|
this.ready.then(() => {
|
|
631
|
-
this.setAlert(
|
|
624
|
+
this.setAlert("alert alert-danger", "Form schema is for a newer version, please upgrade your renderer. Some functionality may not work.");
|
|
632
625
|
});
|
|
633
626
|
}
|
|
634
627
|
// See if they pass a module, and evaluate it if so.
|
|
635
628
|
if (form && form.module) {
|
|
636
629
|
let formModule = null;
|
|
637
|
-
if (typeof form.module ===
|
|
630
|
+
if (typeof form.module === "string") {
|
|
638
631
|
try {
|
|
639
632
|
formModule = this.evaluate(`return ${form.module}`);
|
|
640
633
|
}
|
|
@@ -656,7 +649,7 @@ export default class Webform extends NestedDataComponent {
|
|
|
656
649
|
this.initialized = false;
|
|
657
650
|
const rebuild = this.rebuild() || Promise.resolve();
|
|
658
651
|
return rebuild.then(() => {
|
|
659
|
-
this.emit(
|
|
652
|
+
this.emit("formLoad", form);
|
|
660
653
|
this.triggerCaptcha();
|
|
661
654
|
// Make sure to trigger onChange after a render event occurs to speed up form rendering.
|
|
662
655
|
setTimeout(() => {
|
|
@@ -668,37 +661,33 @@ export default class Webform extends NestedDataComponent {
|
|
|
668
661
|
}
|
|
669
662
|
/**
|
|
670
663
|
* Gets the form object.
|
|
671
|
-
*
|
|
672
|
-
* @returns {Object} - The form JSON schema.
|
|
664
|
+
* @returns {object} - The form JSON schema.
|
|
673
665
|
*/
|
|
674
666
|
get form() {
|
|
675
667
|
if (!this._form) {
|
|
676
668
|
this._form = {
|
|
677
|
-
components: []
|
|
669
|
+
components: [],
|
|
678
670
|
};
|
|
679
671
|
}
|
|
680
672
|
return this._form;
|
|
681
673
|
}
|
|
682
674
|
/**
|
|
683
675
|
* Sets the form value.
|
|
684
|
-
*
|
|
685
676
|
* @alias setForm
|
|
686
|
-
* @param {
|
|
677
|
+
* @param {object} form - The form schema object.
|
|
687
678
|
*/
|
|
688
679
|
set form(form) {
|
|
689
680
|
this.setForm(form);
|
|
690
681
|
}
|
|
691
682
|
/**
|
|
692
683
|
* Returns the submission object that was set within this form.
|
|
693
|
-
*
|
|
694
|
-
* @returns {Object}
|
|
684
|
+
* @returns {object} - The submission object.
|
|
695
685
|
*/
|
|
696
686
|
get submission() {
|
|
697
687
|
return this.getValue();
|
|
698
688
|
}
|
|
699
689
|
/**
|
|
700
690
|
* Sets the submission of a form.
|
|
701
|
-
*
|
|
702
691
|
* @example
|
|
703
692
|
* import Webform from '@formio/js/Webform';
|
|
704
693
|
* let form = new Webform(document.getElementById('formio'));
|
|
@@ -708,121 +697,133 @@ export default class Webform extends NestedDataComponent {
|
|
|
708
697
|
* lastName: 'Smith',
|
|
709
698
|
* email: 'joe@example.com'
|
|
710
699
|
* }};
|
|
711
|
-
*
|
|
712
|
-
* @param {Object} submission - The Form.io submission object.
|
|
700
|
+
* @param {object} submission - The Form.io submission object.
|
|
713
701
|
*/
|
|
714
702
|
set submission(submission) {
|
|
715
703
|
this.setSubmission(submission);
|
|
716
704
|
}
|
|
705
|
+
/**
|
|
706
|
+
* Sets the submission value
|
|
707
|
+
* @param {object|null|undefined} submission - The submission to set.
|
|
708
|
+
* @param {object|null|undefined} flags - Any flags to apply when setting the submission.
|
|
709
|
+
* @returns {void}
|
|
710
|
+
*/
|
|
711
|
+
onSetSubmission(submission, flags = {}) {
|
|
712
|
+
this.submissionSet = true;
|
|
713
|
+
this.triggerChange(flags);
|
|
714
|
+
this.emit('beforeSetSubmission', submission);
|
|
715
|
+
this.setValue(submission, flags);
|
|
716
|
+
}
|
|
717
717
|
/**
|
|
718
718
|
* Sets a submission and returns the promise when it is ready.
|
|
719
|
-
* @param submission
|
|
720
|
-
* @param flags
|
|
721
|
-
* @
|
|
719
|
+
* @param {any} submission - The submission to set.
|
|
720
|
+
* @param {any} flags - Any flags to apply when setting the submission.
|
|
721
|
+
* @returns {Promise} - The promise that is triggered when the submission is set.
|
|
722
722
|
*/
|
|
723
723
|
setSubmission(submission, flags = {}) {
|
|
724
724
|
flags = {
|
|
725
725
|
...flags,
|
|
726
|
-
fromSubmission: _.has(flags,
|
|
726
|
+
fromSubmission: _.has(flags, "fromSubmission") ? flags.fromSubmission : true,
|
|
727
727
|
};
|
|
728
|
-
return this.onSubmission = this.formReady
|
|
728
|
+
return (this.onSubmission = this.formReady
|
|
729
|
+
.then((resolveFlags) => {
|
|
729
730
|
if (resolveFlags) {
|
|
730
731
|
flags = {
|
|
731
732
|
...flags,
|
|
732
|
-
...resolveFlags
|
|
733
|
+
...resolveFlags,
|
|
733
734
|
};
|
|
734
735
|
}
|
|
735
|
-
this.
|
|
736
|
-
this.triggerChange(flags);
|
|
737
|
-
this.emit('beforeSetSubmission', submission);
|
|
738
|
-
this.setValue(submission, flags);
|
|
736
|
+
this.onSetSubmission(submission, flags);
|
|
739
737
|
return this.submissionReadyResolve(submission);
|
|
740
|
-
}, (err) => this.submissionReadyReject(err))
|
|
738
|
+
}, (err) => this.submissionReadyReject(err))
|
|
739
|
+
.catch((err) => this.submissionReadyReject(err)));
|
|
741
740
|
}
|
|
742
741
|
handleDraftError(errName, errDetails, restoreDraft) {
|
|
743
|
-
const errorMessage = _.trim(`${this.t(errName)} ${errDetails ||
|
|
742
|
+
const errorMessage = _.trim(`${this.t(errName)} ${errDetails || ""}`);
|
|
744
743
|
console.warn(errorMessage);
|
|
745
|
-
this.emit(restoreDraft ?
|
|
744
|
+
this.emit(restoreDraft ? "restoreDraftError" : "saveDraftError", errDetails || errorMessage);
|
|
746
745
|
}
|
|
747
|
-
/**
|
|
748
|
-
* Saves a submission draft.
|
|
749
|
-
*/
|
|
750
746
|
saveDraft() {
|
|
751
747
|
if (!this.draftEnabled) {
|
|
752
748
|
return;
|
|
753
749
|
}
|
|
754
750
|
if (!this.formio) {
|
|
755
|
-
this.handleDraftError(
|
|
751
|
+
this.handleDraftError("saveDraftInstanceError");
|
|
756
752
|
return;
|
|
757
753
|
}
|
|
758
754
|
if (!Formio.getUser()) {
|
|
759
|
-
this.handleDraftError(
|
|
755
|
+
this.handleDraftError("saveDraftAuthError");
|
|
760
756
|
return;
|
|
761
757
|
}
|
|
762
758
|
const draft = fastCloneDeep(this.submission);
|
|
763
|
-
draft.state =
|
|
759
|
+
draft.state = "draft";
|
|
764
760
|
if (!this.savingDraft && !this.submitting) {
|
|
765
|
-
this.emit(
|
|
761
|
+
this.emit("saveDraftBegin");
|
|
766
762
|
this.savingDraft = true;
|
|
767
|
-
this.formio
|
|
763
|
+
this.formio
|
|
764
|
+
.saveSubmission(draft)
|
|
765
|
+
.then((sub) => {
|
|
768
766
|
// Set id to submission to avoid creating new draft submission
|
|
769
767
|
this.submission._id = sub._id;
|
|
770
768
|
this.savingDraft = false;
|
|
771
|
-
this.emit(
|
|
769
|
+
this.emit("saveDraft", sub);
|
|
772
770
|
})
|
|
773
|
-
.catch(err => {
|
|
771
|
+
.catch((err) => {
|
|
774
772
|
this.savingDraft = false;
|
|
775
|
-
this.handleDraftError(
|
|
773
|
+
this.handleDraftError("saveDraftError", err);
|
|
776
774
|
});
|
|
777
775
|
}
|
|
778
776
|
}
|
|
779
777
|
/**
|
|
780
778
|
* Restores a draft submission based on the user who is authenticated.
|
|
781
|
-
*
|
|
782
|
-
* @param {userId} - The user id where we need to restore the draft from.
|
|
779
|
+
* @param {string} userId - The user id where we need to restore the draft from.
|
|
783
780
|
*/
|
|
784
781
|
restoreDraft(userId) {
|
|
785
782
|
const formio = this.formio || this.options.formio;
|
|
786
783
|
if (!formio) {
|
|
787
|
-
this.handleDraftError(
|
|
784
|
+
this.handleDraftError("restoreDraftInstanceError", null, true);
|
|
788
785
|
return;
|
|
789
786
|
}
|
|
790
787
|
this.savingDraft = true;
|
|
791
|
-
formio
|
|
788
|
+
formio
|
|
789
|
+
.loadSubmissions({
|
|
792
790
|
params: {
|
|
793
791
|
state: 'draft',
|
|
794
792
|
owner: userId,
|
|
795
793
|
sort: '-created'
|
|
796
|
-
}
|
|
797
|
-
})
|
|
794
|
+
},
|
|
795
|
+
})
|
|
796
|
+
.then((submissions) => {
|
|
798
797
|
if (submissions.length > 0 && !this.options.skipDraftRestore) {
|
|
799
798
|
const draft = fastCloneDeep(submissions[0]);
|
|
800
799
|
return this.setSubmission(draft).then(() => {
|
|
801
800
|
this.draftEnabled = true;
|
|
802
801
|
this.savingDraft = false;
|
|
803
|
-
this.emit(
|
|
802
|
+
this.emit("restoreDraft", draft);
|
|
804
803
|
});
|
|
805
804
|
}
|
|
806
805
|
// Enable drafts so that we can keep track of changes.
|
|
807
806
|
this.draftEnabled = true;
|
|
808
807
|
this.savingDraft = false;
|
|
809
|
-
this.emit(
|
|
808
|
+
this.emit("restoreDraft", null);
|
|
810
809
|
})
|
|
811
|
-
.catch(err => {
|
|
810
|
+
.catch((err) => {
|
|
812
811
|
this.draftEnabled = true;
|
|
813
812
|
this.savingDraft = false;
|
|
814
|
-
this.handleDraftError(
|
|
813
|
+
this.handleDraftError("restoreDraftError", err, true);
|
|
815
814
|
});
|
|
816
815
|
}
|
|
817
816
|
get schema() {
|
|
818
|
-
const schema = fastCloneDeep(_.omit(this._form, [
|
|
817
|
+
const schema = fastCloneDeep(_.omit(this._form, ["components"]));
|
|
819
818
|
schema.components = [];
|
|
820
819
|
this.eachComponent((component) => schema.components.push(component.schema));
|
|
821
820
|
return schema;
|
|
822
821
|
}
|
|
823
822
|
mergeData(_this, _that) {
|
|
824
823
|
_.mergeWith(_this, _that, (thisValue, thatValue) => {
|
|
825
|
-
if (Array.isArray(thisValue) &&
|
|
824
|
+
if (Array.isArray(thisValue) &&
|
|
825
|
+
Array.isArray(thatValue) &&
|
|
826
|
+
thisValue.length !== thatValue.length) {
|
|
826
827
|
return thatValue;
|
|
827
828
|
}
|
|
828
829
|
});
|
|
@@ -835,9 +836,7 @@ export default class Webform extends NestedDataComponent {
|
|
|
835
836
|
};
|
|
836
837
|
}
|
|
837
838
|
// Metadata needs to be available before setValue
|
|
838
|
-
this._submission.metadata = submission.metadata
|
|
839
|
-
? _.cloneDeep(submission.metadata)
|
|
840
|
-
: {};
|
|
839
|
+
this._submission.metadata = submission.metadata ? _.cloneDeep(submission.metadata) : {};
|
|
841
840
|
this.editing = !!submission._id;
|
|
842
841
|
// Set the timezone in the options if available.
|
|
843
842
|
if (!this.options.submissionTimezone &&
|
|
@@ -866,6 +865,7 @@ export default class Webform extends NestedDataComponent {
|
|
|
866
865
|
}
|
|
867
866
|
/**
|
|
868
867
|
* Build the form.
|
|
868
|
+
* @returns {Promise} - The promise that is triggered when the form is built.
|
|
869
869
|
*/
|
|
870
870
|
init() {
|
|
871
871
|
if (this.options.submission) {
|
|
@@ -887,28 +887,33 @@ export default class Webform extends NestedDataComponent {
|
|
|
887
887
|
else {
|
|
888
888
|
this.component = this.form;
|
|
889
889
|
}
|
|
890
|
-
this.component.type =
|
|
890
|
+
this.component.type = "form";
|
|
891
891
|
this.component.input = false;
|
|
892
892
|
this.addComponents();
|
|
893
|
-
this.on(
|
|
894
|
-
this.submit(false, options).catch(e => {
|
|
895
|
-
options
|
|
893
|
+
this.on("submitButton", (options) => {
|
|
894
|
+
this.submit(false, options).catch((e) => {
|
|
895
|
+
if (options?.instance) {
|
|
896
|
+
options.instance.loading = false;
|
|
897
|
+
}
|
|
896
898
|
return e !== false && e !== undefined && console.log(e);
|
|
897
899
|
});
|
|
898
900
|
}, true);
|
|
899
|
-
this.on(
|
|
900
|
-
this.on(
|
|
901
|
-
this.on(
|
|
902
|
-
this.on(
|
|
903
|
-
this.on(
|
|
901
|
+
this.on("checkValidity", (data) => this.validate(data, { dirty: true, process: "change" }), true);
|
|
902
|
+
this.on("requestUrl", (args) => this.submitUrl(args.url, args.headers), true);
|
|
903
|
+
this.on("resetForm", () => this.resetValue(), true);
|
|
904
|
+
this.on("deleteSubmission", () => this.deleteSubmission(), true);
|
|
905
|
+
this.on("refreshData", () => this.updateValue(), true);
|
|
904
906
|
this.executeFormController();
|
|
905
907
|
return this.formReady;
|
|
906
908
|
}
|
|
907
909
|
executeFormController() {
|
|
908
910
|
// If no controller value or
|
|
909
911
|
// hidden and set to clearOnHide (Don't calculate a value for a hidden field set to clear when hidden)
|
|
910
|
-
if (!this.form ||
|
|
911
|
-
|
|
912
|
+
if (!this.form ||
|
|
913
|
+
!this.form.controller ||
|
|
914
|
+
((!this.visible || this.component.hidden) &&
|
|
915
|
+
this.component.clearOnHide &&
|
|
916
|
+
!this.rootPristine)) {
|
|
912
917
|
return false;
|
|
913
918
|
}
|
|
914
919
|
this.formReady.then(() => {
|
|
@@ -918,20 +923,23 @@ export default class Webform extends NestedDataComponent {
|
|
|
918
923
|
});
|
|
919
924
|
});
|
|
920
925
|
}
|
|
926
|
+
/**
|
|
927
|
+
*
|
|
928
|
+
*/
|
|
921
929
|
teardown() {
|
|
922
|
-
this.emit(
|
|
930
|
+
this.emit("formDelete", this.id);
|
|
923
931
|
delete Formio.forms[this.id];
|
|
924
932
|
delete this.executeShortcuts;
|
|
925
933
|
delete this.triggerSaveDraft;
|
|
926
934
|
super.teardown();
|
|
927
935
|
}
|
|
928
936
|
destroy(all = false) {
|
|
929
|
-
this.off(
|
|
930
|
-
this.off(
|
|
931
|
-
this.off(
|
|
932
|
-
this.off(
|
|
933
|
-
this.off(
|
|
934
|
-
this.off(
|
|
937
|
+
this.off("submitButton");
|
|
938
|
+
this.off("checkValidity");
|
|
939
|
+
this.off("requestUrl");
|
|
940
|
+
this.off("resetForm");
|
|
941
|
+
this.off("deleteSubmission");
|
|
942
|
+
this.off("refreshData");
|
|
935
943
|
return super.destroy(all);
|
|
936
944
|
}
|
|
937
945
|
build(element) {
|
|
@@ -944,17 +952,17 @@ export default class Webform extends NestedDataComponent {
|
|
|
944
952
|
return this.ready;
|
|
945
953
|
}
|
|
946
954
|
getClassName() {
|
|
947
|
-
let classes =
|
|
955
|
+
let classes = "formio-form";
|
|
948
956
|
if (this.options.readOnly) {
|
|
949
|
-
classes +=
|
|
957
|
+
classes += " formio-read-only";
|
|
950
958
|
}
|
|
951
959
|
return classes;
|
|
952
960
|
}
|
|
953
961
|
render() {
|
|
954
|
-
return super.render(this.renderTemplate(
|
|
962
|
+
return super.render(this.renderTemplate("webform", {
|
|
955
963
|
classes: this.getClassName(),
|
|
956
964
|
children: this.renderComponents(),
|
|
957
|
-
}), this.builderMode ?
|
|
965
|
+
}), this.builderMode ? "builder" : "form", true);
|
|
958
966
|
}
|
|
959
967
|
redraw() {
|
|
960
968
|
// Don't bother if we have not built yet.
|
|
@@ -967,13 +975,13 @@ export default class Webform extends NestedDataComponent {
|
|
|
967
975
|
}
|
|
968
976
|
attach(element) {
|
|
969
977
|
this.setElement(element);
|
|
970
|
-
this.loadRefs(element, { webform:
|
|
978
|
+
this.loadRefs(element, { webform: "single" });
|
|
971
979
|
const childPromise = this.attachComponents(this.refs.webform);
|
|
972
|
-
this.addEventListener(document,
|
|
980
|
+
this.addEventListener(document, "keydown", this.executeShortcuts);
|
|
973
981
|
this.currentForm = this;
|
|
974
|
-
this.hook(
|
|
982
|
+
this.hook("attachWebform", element, this);
|
|
975
983
|
return childPromise.then(() => {
|
|
976
|
-
this.emit(
|
|
984
|
+
this.emit("render", this.element);
|
|
977
985
|
return this.setValue(this._submission, {
|
|
978
986
|
noUpdateEvent: true,
|
|
979
987
|
});
|
|
@@ -990,24 +998,23 @@ export default class Webform extends NestedDataComponent {
|
|
|
990
998
|
return result;
|
|
991
999
|
}
|
|
992
1000
|
resetValue() {
|
|
993
|
-
_.each(this.getComponents(), (comp) =>
|
|
1001
|
+
_.each(this.getComponents(), (comp) => comp.resetValue());
|
|
994
1002
|
this.setPristine(true);
|
|
995
1003
|
this.onChange({ resetValue: true });
|
|
996
1004
|
}
|
|
997
1005
|
/**
|
|
998
1006
|
* Sets a new alert to display in the error dialog of the form.
|
|
999
|
-
*
|
|
1000
1007
|
* @param {string} type - The type of alert to display. "danger", "success", "warning", etc.
|
|
1001
1008
|
* @param {string} message - The message to show in the alert.
|
|
1002
|
-
* @param {
|
|
1009
|
+
* @param {object} options - The options for the alert.
|
|
1003
1010
|
*/
|
|
1004
1011
|
setAlert(type, message, options) {
|
|
1005
1012
|
if (!type && this.submitted) {
|
|
1006
1013
|
if (this.alert) {
|
|
1007
1014
|
if (this.refs.errorRef && this.refs.errorRef.length) {
|
|
1008
|
-
this.refs.errorRef.forEach(el => {
|
|
1009
|
-
this.removeEventListener(el,
|
|
1010
|
-
this.removeEventListener(el,
|
|
1015
|
+
this.refs.errorRef.forEach((el) => {
|
|
1016
|
+
this.removeEventListener(el, "click");
|
|
1017
|
+
this.removeEventListener(el, "keypress");
|
|
1011
1018
|
});
|
|
1012
1019
|
}
|
|
1013
1020
|
this.removeChild(this.alert);
|
|
@@ -1017,16 +1024,16 @@ export default class Webform extends NestedDataComponent {
|
|
|
1017
1024
|
}
|
|
1018
1025
|
if (this.options.noAlerts) {
|
|
1019
1026
|
if (!message) {
|
|
1020
|
-
this.emit(
|
|
1027
|
+
this.emit("error", false);
|
|
1021
1028
|
}
|
|
1022
1029
|
return;
|
|
1023
1030
|
}
|
|
1024
1031
|
if (this.alert) {
|
|
1025
1032
|
try {
|
|
1026
1033
|
if (this.refs.errorRef && this.refs.errorRef.length) {
|
|
1027
|
-
this.refs.errorRef.forEach(el => {
|
|
1028
|
-
this.removeEventListener(el,
|
|
1029
|
-
this.removeEventListener(el,
|
|
1034
|
+
this.refs.errorRef.forEach((el) => {
|
|
1035
|
+
this.removeEventListener(el, "click");
|
|
1036
|
+
this.removeEventListener(el, "keypress");
|
|
1030
1037
|
});
|
|
1031
1038
|
}
|
|
1032
1039
|
this.removeChild(this.alert);
|
|
@@ -1044,21 +1051,21 @@ export default class Webform extends NestedDataComponent {
|
|
|
1044
1051
|
const templateOptions = {
|
|
1045
1052
|
message: message instanceof HTMLElement ? message.outerHTML : message,
|
|
1046
1053
|
attrs: attrs,
|
|
1047
|
-
type
|
|
1054
|
+
type,
|
|
1048
1055
|
};
|
|
1049
|
-
this.alert = convertStringToHTMLElement(this.renderTemplate(
|
|
1056
|
+
this.alert = convertStringToHTMLElement(this.renderTemplate("alert", templateOptions), `#${attrs.id}`);
|
|
1050
1057
|
}
|
|
1051
1058
|
if (!this.alert) {
|
|
1052
1059
|
return;
|
|
1053
1060
|
}
|
|
1054
|
-
this.loadRefs(this.alert, { errorRef:
|
|
1061
|
+
this.loadRefs(this.alert, { errorRef: "multiple" });
|
|
1055
1062
|
if (this.refs.errorRef && this.refs.errorRef.length) {
|
|
1056
|
-
this.refs.errorRef.forEach(el => {
|
|
1057
|
-
this.addEventListener(el,
|
|
1063
|
+
this.refs.errorRef.forEach((el) => {
|
|
1064
|
+
this.addEventListener(el, "click", (e) => {
|
|
1058
1065
|
const key = e.currentTarget.dataset.componentKey;
|
|
1059
1066
|
this.focusOnComponent(key);
|
|
1060
1067
|
});
|
|
1061
|
-
this.addEventListener(el,
|
|
1068
|
+
this.addEventListener(el, "keydown", (e) => {
|
|
1062
1069
|
if (e.keyCode === 13) {
|
|
1063
1070
|
e.preventDefault();
|
|
1064
1071
|
const key = e.currentTarget.dataset.componentKey;
|
|
@@ -1071,9 +1078,7 @@ export default class Webform extends NestedDataComponent {
|
|
|
1071
1078
|
}
|
|
1072
1079
|
/**
|
|
1073
1080
|
* Focus on selected component.
|
|
1074
|
-
*
|
|
1075
1081
|
* @param {string} key - The key of selected component.
|
|
1076
|
-
* @returns {*}
|
|
1077
1082
|
*/
|
|
1078
1083
|
focusOnComponent(key) {
|
|
1079
1084
|
if (key) {
|
|
@@ -1085,11 +1090,16 @@ export default class Webform extends NestedDataComponent {
|
|
|
1085
1090
|
}
|
|
1086
1091
|
/**
|
|
1087
1092
|
* Show the errors of this form within the alert dialog.
|
|
1088
|
-
*
|
|
1089
|
-
* @param {Object} error - An optional additional error to display along with the component errors.
|
|
1093
|
+
* @param {object} error - An optional additional error to display along with the component errors.
|
|
1090
1094
|
* @returns {*}
|
|
1091
1095
|
*/
|
|
1092
1096
|
/* eslint-disable no-unused-vars */
|
|
1097
|
+
/**
|
|
1098
|
+
*
|
|
1099
|
+
* @param {Array} errors - An array of errors to display.
|
|
1100
|
+
* @param {boolean} triggerEvent - Whether or not to trigger the error event.
|
|
1101
|
+
* @returns {void|Array} - The errors that were set.
|
|
1102
|
+
*/
|
|
1093
1103
|
showErrors(errors, triggerEvent) {
|
|
1094
1104
|
this.loading = false;
|
|
1095
1105
|
if (!Array.isArray(errors)) {
|
|
@@ -1126,42 +1136,46 @@ export default class Webform extends NestedDataComponent {
|
|
|
1126
1136
|
});
|
|
1127
1137
|
const displayedErrors = [];
|
|
1128
1138
|
if (errors.length) {
|
|
1129
|
-
errors = _.uniqBy(errors, error => error.message);
|
|
1139
|
+
errors = _.uniqBy(errors, (error) => error.message);
|
|
1130
1140
|
const createListItem = (message, index) => {
|
|
1131
1141
|
const err = errors[index];
|
|
1132
1142
|
const messageFromIndex = !_.isUndefined(index) && errors && errors[index];
|
|
1133
|
-
const keyOrPath =
|
|
1134
|
-
|
|
1135
|
-
|
|
1143
|
+
const keyOrPath = messageFromIndex?.formattedKeyOrPath ||
|
|
1144
|
+
messageFromIndex?.path ||
|
|
1145
|
+
messageFromIndex?.context?.path ||
|
|
1146
|
+
(err.context?.component && err.context?.component.key) ||
|
|
1147
|
+
(err.component && err.component.key) ||
|
|
1148
|
+
(err.fromServer && err.path);
|
|
1149
|
+
const formattedKeyOrPath = keyOrPath ? getStringFromComponentPath(keyOrPath) : "";
|
|
1150
|
+
if (typeof err !== "string" && !err.formattedKeyOrPath) {
|
|
1136
1151
|
err.formattedKeyOrPath = formattedKeyOrPath;
|
|
1137
1152
|
}
|
|
1138
1153
|
return {
|
|
1139
1154
|
message: unescapeHTML(message),
|
|
1140
|
-
keyOrPath: formattedKeyOrPath
|
|
1155
|
+
keyOrPath: formattedKeyOrPath,
|
|
1141
1156
|
};
|
|
1142
1157
|
};
|
|
1143
1158
|
errors.forEach(({ message, context, fromServer, component }, index) => {
|
|
1144
1159
|
const text = !component?.label || context?.hasLabel || fromServer
|
|
1145
|
-
? this.t(
|
|
1146
|
-
: this.t(
|
|
1160
|
+
? this.t("alertMessage", { message: this.t(message) })
|
|
1161
|
+
: this.t("alertMessageWithLabel", {
|
|
1147
1162
|
label: this.t(component?.label),
|
|
1148
1163
|
message: this.t(message),
|
|
1149
1164
|
});
|
|
1150
1165
|
displayedErrors.push(createListItem(text, index));
|
|
1151
1166
|
});
|
|
1152
1167
|
}
|
|
1153
|
-
const errorsList = this.renderTemplate(
|
|
1154
|
-
this.root.setAlert(
|
|
1168
|
+
const errorsList = this.renderTemplate("errorsList", { errors: displayedErrors });
|
|
1169
|
+
this.root.setAlert("danger", errorsList);
|
|
1155
1170
|
if (triggerEvent) {
|
|
1156
|
-
this.emit(
|
|
1171
|
+
this.emit("error", errors);
|
|
1157
1172
|
}
|
|
1158
1173
|
return errors;
|
|
1159
1174
|
}
|
|
1160
1175
|
/* eslint-enable no-unused-vars */
|
|
1161
1176
|
/**
|
|
1162
1177
|
* Called when the submission has completed, or if the submission needs to be sent to an external library.
|
|
1163
|
-
*
|
|
1164
|
-
* @param {Object} submission - The submission object.
|
|
1178
|
+
* @param {object} submission - The submission object.
|
|
1165
1179
|
* @param {boolean} saved - Whether or not this submission was saved to the server.
|
|
1166
1180
|
* @returns {object} - The submission object.
|
|
1167
1181
|
*/
|
|
@@ -1172,25 +1186,25 @@ export default class Webform extends NestedDataComponent {
|
|
|
1172
1186
|
// We want to return the submitted submission and setValue will mutate the submission so cloneDeep it here.
|
|
1173
1187
|
this.setValue(fastCloneDeep(submission), {
|
|
1174
1188
|
noValidate: true,
|
|
1175
|
-
noCheck: true
|
|
1189
|
+
noCheck: true,
|
|
1176
1190
|
});
|
|
1177
|
-
this.setAlert(
|
|
1191
|
+
this.setAlert("success", `<p>${this.t("complete")}</p>`);
|
|
1178
1192
|
// Cancel triggered saveDraft to prevent overriding the submitted state
|
|
1179
1193
|
if (this.draftEnabled && this.triggerSaveDraft?.cancel) {
|
|
1180
1194
|
this.triggerSaveDraft.cancel();
|
|
1181
1195
|
}
|
|
1182
|
-
this.emit(
|
|
1196
|
+
this.emit("submit", submission, saved);
|
|
1183
1197
|
if (saved) {
|
|
1184
|
-
this.emit(
|
|
1198
|
+
this.emit("submitDone", submission);
|
|
1185
1199
|
}
|
|
1186
1200
|
return submission;
|
|
1187
1201
|
}
|
|
1188
1202
|
normalizeError(error) {
|
|
1189
1203
|
if (error) {
|
|
1190
|
-
if (typeof error ===
|
|
1204
|
+
if (typeof error === "object" && "details" in error) {
|
|
1191
1205
|
error = error.details;
|
|
1192
1206
|
}
|
|
1193
|
-
if (typeof error ===
|
|
1207
|
+
if (typeof error === "string") {
|
|
1194
1208
|
error = { message: error };
|
|
1195
1209
|
}
|
|
1196
1210
|
}
|
|
@@ -1198,17 +1212,17 @@ export default class Webform extends NestedDataComponent {
|
|
|
1198
1212
|
}
|
|
1199
1213
|
/**
|
|
1200
1214
|
* Called when an error occurs during the submission.
|
|
1201
|
-
*
|
|
1202
|
-
* @
|
|
1215
|
+
* @param {object} error - The error that occured.
|
|
1216
|
+
* @returns {Array} errors - All errors.
|
|
1203
1217
|
*/
|
|
1204
1218
|
onSubmissionError(error) {
|
|
1205
1219
|
error = this.normalizeError(error);
|
|
1206
1220
|
this.submitting = false;
|
|
1207
1221
|
this.setPristine(false);
|
|
1208
|
-
this.emit(
|
|
1222
|
+
this.emit("submitError", error || this.errors);
|
|
1209
1223
|
// Allow for silent cancellations (no error message, no submit button error state)
|
|
1210
1224
|
if (error && error.silent) {
|
|
1211
|
-
this.emit(
|
|
1225
|
+
this.emit("change", { isValid: true }, { silent: true });
|
|
1212
1226
|
return false;
|
|
1213
1227
|
}
|
|
1214
1228
|
const errors = this.showErrors(error, true);
|
|
@@ -1219,9 +1233,10 @@ export default class Webform extends NestedDataComponent {
|
|
|
1219
1233
|
}
|
|
1220
1234
|
/**
|
|
1221
1235
|
* Trigger the change event for this form.
|
|
1222
|
-
*
|
|
1223
|
-
* @param changed
|
|
1224
|
-
* @param
|
|
1236
|
+
* @param {any} flags - The flags to set on this change event.
|
|
1237
|
+
* @param {any} changed - The changed object which reflects the changes in the form.
|
|
1238
|
+
* @param {boolean} modified - Whether or not the form has been modified.
|
|
1239
|
+
* @param {any} changes - The changes that have occured in the form.
|
|
1225
1240
|
*/
|
|
1226
1241
|
onChange(flags, changed, modified, changes) {
|
|
1227
1242
|
flags = flags || {};
|
|
@@ -1234,13 +1249,17 @@ export default class Webform extends NestedDataComponent {
|
|
|
1234
1249
|
this.pristine = false;
|
|
1235
1250
|
}
|
|
1236
1251
|
this.checkData(value.data, flags);
|
|
1237
|
-
const shouldValidate = !flags.noValidate ||
|
|
1238
|
-
|
|
1252
|
+
const shouldValidate = !flags.noValidate ||
|
|
1253
|
+
flags.fromIFrame ||
|
|
1254
|
+
(flags.fromSubmission && this.rootPristine && this.pristine && flags.changed);
|
|
1255
|
+
const errors = shouldValidate
|
|
1256
|
+
? this.validate(value.data, { ...flags, process: "change" })
|
|
1257
|
+
: [];
|
|
1239
1258
|
value.isValid = errors.length === 0;
|
|
1240
1259
|
this.loading = false;
|
|
1241
1260
|
if (this.submitted) {
|
|
1242
1261
|
// show server errors while they are not cleaned/fixed
|
|
1243
|
-
const nonComponentServerErrors = _.filter(this.serverErrors || [], err => !err.component && !err.path);
|
|
1262
|
+
const nonComponentServerErrors = _.filter(this.serverErrors || [], (err) => !err.component && !err.path);
|
|
1244
1263
|
this.showErrors(nonComponentServerErrors.length ? nonComponentServerErrors : errors);
|
|
1245
1264
|
}
|
|
1246
1265
|
// See if we need to save the draft of the form.
|
|
@@ -1248,38 +1267,39 @@ export default class Webform extends NestedDataComponent {
|
|
|
1248
1267
|
this.triggerSaveDraft();
|
|
1249
1268
|
}
|
|
1250
1269
|
if (!flags || !flags.noEmit) {
|
|
1251
|
-
this.emit(
|
|
1270
|
+
this.emit("change", value, flags, modified);
|
|
1252
1271
|
isChangeEventEmitted = true;
|
|
1253
1272
|
}
|
|
1254
1273
|
// The form is initialized after the first change event occurs.
|
|
1255
1274
|
if (isChangeEventEmitted && !this.initialized) {
|
|
1256
|
-
this.emit(
|
|
1275
|
+
this.emit("initialized");
|
|
1257
1276
|
this.initialized = true;
|
|
1258
1277
|
}
|
|
1259
1278
|
}
|
|
1260
1279
|
/**
|
|
1261
1280
|
* Send a delete request to the server.
|
|
1281
|
+
* @returns {Promise} - The promise that is triggered when the delete is complete.
|
|
1262
1282
|
*/
|
|
1263
1283
|
deleteSubmission() {
|
|
1264
|
-
return this.formio.deleteSubmission()
|
|
1265
|
-
.
|
|
1266
|
-
this.emit('submissionDeleted', this.submission);
|
|
1284
|
+
return this.formio.deleteSubmission().then(() => {
|
|
1285
|
+
this.emit("submissionDeleted", this.submission);
|
|
1267
1286
|
this.resetValue();
|
|
1268
1287
|
});
|
|
1269
1288
|
}
|
|
1270
1289
|
/**
|
|
1271
1290
|
* Cancels the submission.
|
|
1272
|
-
*
|
|
1291
|
+
* @param {boolean} noconfirm - Whether or not to confirm the cancellation.
|
|
1273
1292
|
* @alias reset
|
|
1293
|
+
* @returns {boolean} - TRUE means the submission was cancelled, FALSE otherwise.
|
|
1274
1294
|
*/
|
|
1275
1295
|
cancel(noconfirm) {
|
|
1276
|
-
const shouldReset = this.hook(
|
|
1277
|
-
if (shouldReset && (noconfirm || confirm(this.t(
|
|
1296
|
+
const shouldReset = this.hook("beforeCancel", true);
|
|
1297
|
+
if (shouldReset && (noconfirm || confirm(this.t("confirmCancel")))) {
|
|
1278
1298
|
this.resetValue();
|
|
1279
1299
|
return true;
|
|
1280
1300
|
}
|
|
1281
1301
|
else {
|
|
1282
|
-
this.emit(
|
|
1302
|
+
this.emit("cancelSubmit");
|
|
1283
1303
|
return false;
|
|
1284
1304
|
}
|
|
1285
1305
|
}
|
|
@@ -1287,14 +1307,14 @@ export default class Webform extends NestedDataComponent {
|
|
|
1287
1307
|
// Add in metadata about client submitting the form
|
|
1288
1308
|
submission.metadata = submission.metadata || {};
|
|
1289
1309
|
_.defaults(submission.metadata, {
|
|
1290
|
-
timezone: _.get(this,
|
|
1291
|
-
offset: parseInt(_.get(this,
|
|
1310
|
+
timezone: _.get(this, "_submission.metadata.timezone", currentTimezone()),
|
|
1311
|
+
offset: parseInt(_.get(this, "_submission.metadata.offset", moment().utcOffset()), 10),
|
|
1292
1312
|
origin: document.location.origin,
|
|
1293
1313
|
referrer: document.referrer,
|
|
1294
1314
|
browserName: navigator.appName,
|
|
1295
1315
|
userAgent: navigator.userAgent,
|
|
1296
1316
|
pathName: window.location.pathname,
|
|
1297
|
-
onLine: navigator.onLine
|
|
1317
|
+
onLine: navigator.onLine,
|
|
1298
1318
|
});
|
|
1299
1319
|
}
|
|
1300
1320
|
submitForm(options = {}) {
|
|
@@ -1304,29 +1324,30 @@ export default class Webform extends NestedDataComponent {
|
|
|
1304
1324
|
if (this.options.readOnly) {
|
|
1305
1325
|
return resolve({
|
|
1306
1326
|
submission: this.submission,
|
|
1307
|
-
saved: false
|
|
1327
|
+
saved: false,
|
|
1308
1328
|
});
|
|
1309
1329
|
}
|
|
1310
1330
|
const submission = fastCloneDeep(this.submission || {});
|
|
1311
1331
|
this.setMetadata(submission);
|
|
1312
|
-
submission.state = options.state || submission.state ||
|
|
1313
|
-
const isDraft =
|
|
1314
|
-
this.hook(
|
|
1332
|
+
submission.state = options.state || submission.state || "submitted";
|
|
1333
|
+
const isDraft = submission.state === "draft";
|
|
1334
|
+
this.hook("beforeSubmit", { ...submission, component: options.component }, (err, data) => {
|
|
1315
1335
|
if (err) {
|
|
1316
1336
|
return reject(err);
|
|
1317
1337
|
}
|
|
1318
|
-
submission._vnote = data && data._vnote ? data._vnote :
|
|
1338
|
+
submission._vnote = data && data._vnote ? data._vnote : "";
|
|
1319
1339
|
try {
|
|
1320
1340
|
if (!isDraft && !options.noValidate) {
|
|
1321
1341
|
if (!submission.data) {
|
|
1322
|
-
return reject(
|
|
1342
|
+
return reject("Invalid Submission");
|
|
1323
1343
|
}
|
|
1324
1344
|
const errors = this.validate(submission.data, {
|
|
1325
1345
|
dirty: true,
|
|
1326
1346
|
silentCheck: false,
|
|
1327
|
-
process:
|
|
1347
|
+
process: "submit",
|
|
1328
1348
|
});
|
|
1329
|
-
if (errors.length ||
|
|
1349
|
+
if (errors.length ||
|
|
1350
|
+
options.beforeSubmitResults?.some((result) => result.status === "rejected")) {
|
|
1330
1351
|
return reject(errors);
|
|
1331
1352
|
}
|
|
1332
1353
|
}
|
|
@@ -1335,20 +1356,20 @@ export default class Webform extends NestedDataComponent {
|
|
|
1335
1356
|
console.error(err);
|
|
1336
1357
|
}
|
|
1337
1358
|
this.everyComponent((comp) => {
|
|
1338
|
-
if (submission._vnote && comp.type ===
|
|
1359
|
+
if (submission._vnote && comp.type === "form" && comp.component.reference) {
|
|
1339
1360
|
_.get(submission.data, comp.path, {})._vnote = submission._vnote;
|
|
1340
1361
|
}
|
|
1341
1362
|
const { persistent } = comp.component;
|
|
1342
|
-
if (persistent ===
|
|
1363
|
+
if (persistent === "client-only") {
|
|
1343
1364
|
_.unset(submission.data, comp.path);
|
|
1344
1365
|
}
|
|
1345
1366
|
});
|
|
1346
|
-
this.hook(
|
|
1367
|
+
this.hook("customValidation", { ...submission, component: options.component }, (err) => {
|
|
1347
1368
|
if (err) {
|
|
1348
1369
|
// If string is returned, cast to object.
|
|
1349
|
-
if (typeof err ===
|
|
1370
|
+
if (typeof err === "string") {
|
|
1350
1371
|
err = {
|
|
1351
|
-
message: err
|
|
1372
|
+
message: err,
|
|
1352
1373
|
};
|
|
1353
1374
|
}
|
|
1354
1375
|
// Ensure err is an array.
|
|
@@ -1358,7 +1379,10 @@ export default class Webform extends NestedDataComponent {
|
|
|
1358
1379
|
this.loading = true;
|
|
1359
1380
|
// Use the form action to submit the form if available.
|
|
1360
1381
|
if (this._form && this._form.action) {
|
|
1361
|
-
const method =
|
|
1382
|
+
const method = submission.data._id &&
|
|
1383
|
+
this._form.action.includes(submission.data._id)
|
|
1384
|
+
? "PUT"
|
|
1385
|
+
: "POST";
|
|
1362
1386
|
return Formio.makeStaticRequest(this._form.action, method, submission, this.formio ? this.formio.options : {})
|
|
1363
1387
|
.then((result) => resolve({
|
|
1364
1388
|
submission: result,
|
|
@@ -1377,7 +1401,9 @@ export default class Webform extends NestedDataComponent {
|
|
|
1377
1401
|
});
|
|
1378
1402
|
}
|
|
1379
1403
|
// If this is an actionUrl, then make sure to save the action and not the submission.
|
|
1380
|
-
const submitMethod = submitFormio.actionUrl
|
|
1404
|
+
const submitMethod = submitFormio.actionUrl
|
|
1405
|
+
? "saveAction"
|
|
1406
|
+
: "saveSubmission";
|
|
1381
1407
|
submitFormio[submitMethod](submission)
|
|
1382
1408
|
.then((result) => resolve({
|
|
1383
1409
|
submission: result,
|
|
@@ -1393,13 +1419,15 @@ export default class Webform extends NestedDataComponent {
|
|
|
1393
1419
|
}
|
|
1394
1420
|
setServerErrors(error) {
|
|
1395
1421
|
if (error.details) {
|
|
1396
|
-
this.serverErrors = error.details
|
|
1422
|
+
this.serverErrors = error.details
|
|
1423
|
+
.filter((err) => (err.level ? err.level === "error" : err))
|
|
1424
|
+
.map((err) => {
|
|
1397
1425
|
err.fromServer = true;
|
|
1398
1426
|
return err;
|
|
1399
1427
|
});
|
|
1400
1428
|
}
|
|
1401
|
-
else if (typeof error ===
|
|
1402
|
-
this.serverErrors = [{ fromServer: true, level:
|
|
1429
|
+
else if (typeof error === "string") {
|
|
1430
|
+
this.serverErrors = [{ fromServer: true, level: "error", message: error }];
|
|
1403
1431
|
}
|
|
1404
1432
|
}
|
|
1405
1433
|
executeSubmit(options) {
|
|
@@ -1430,7 +1458,6 @@ export default class Webform extends NestedDataComponent {
|
|
|
1430
1458
|
}
|
|
1431
1459
|
/**
|
|
1432
1460
|
* Submits the form.
|
|
1433
|
-
*
|
|
1434
1461
|
* @example
|
|
1435
1462
|
* import Webform from '@formio/js/Webform';
|
|
1436
1463
|
* let form = new Webform(document.getElementById('formio'));
|
|
@@ -1443,12 +1470,11 @@ export default class Webform extends NestedDataComponent {
|
|
|
1443
1470
|
* form.submit().then((submission) => {
|
|
1444
1471
|
* console.log(submission);
|
|
1445
1472
|
* });
|
|
1446
|
-
*
|
|
1447
1473
|
* @param {boolean} before - If this submission occured from the before handlers.
|
|
1448
|
-
*
|
|
1474
|
+
* @param {any} options - The options to use when submitting this form.
|
|
1449
1475
|
* @returns {Promise} - A promise when the form is done submitting.
|
|
1450
1476
|
*/
|
|
1451
|
-
submit(before, options = {}) {
|
|
1477
|
+
submit(before = false, options = {}) {
|
|
1452
1478
|
this.submissionInProcess = true;
|
|
1453
1479
|
if (!before) {
|
|
1454
1480
|
return this.beforeSubmit(options).then(() => this.executeSubmit(options));
|
|
@@ -1459,37 +1485,41 @@ export default class Webform extends NestedDataComponent {
|
|
|
1459
1485
|
}
|
|
1460
1486
|
submitUrl(URL, headers) {
|
|
1461
1487
|
if (!URL) {
|
|
1462
|
-
return console.warn(
|
|
1488
|
+
return console.warn("Missing URL argument");
|
|
1463
1489
|
}
|
|
1464
1490
|
const submission = this.submission || {};
|
|
1465
1491
|
const API_URL = URL;
|
|
1466
1492
|
const settings = {
|
|
1467
|
-
method:
|
|
1468
|
-
headers: {}
|
|
1493
|
+
method: "POST",
|
|
1494
|
+
headers: {},
|
|
1469
1495
|
};
|
|
1470
1496
|
if (headers && headers.length > 0) {
|
|
1471
1497
|
headers.map((e) => {
|
|
1472
|
-
if (e.header !==
|
|
1498
|
+
if (e.header !== "" && e.value !== "") {
|
|
1473
1499
|
settings.headers[e.header] = this.interpolate(e.value, submission);
|
|
1474
1500
|
}
|
|
1475
1501
|
});
|
|
1476
1502
|
}
|
|
1477
1503
|
if (API_URL && settings) {
|
|
1478
|
-
Formio.makeStaticRequest(API_URL, settings.method, submission, {
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
this.
|
|
1504
|
+
Formio.makeStaticRequest(API_URL, settings.method, submission, {
|
|
1505
|
+
headers: settings.headers,
|
|
1506
|
+
})
|
|
1507
|
+
.then(() => {
|
|
1508
|
+
this.emit("requestDone");
|
|
1509
|
+
this.setAlert("success", "<p> Success </p>");
|
|
1510
|
+
})
|
|
1511
|
+
.catch((e) => {
|
|
1512
|
+
const message = `${e.statusText ? e.statusText : ""} ${e.status ? e.status : e}`;
|
|
1513
|
+
this.emit("error", message);
|
|
1484
1514
|
console.error(message);
|
|
1485
|
-
this.setAlert(
|
|
1515
|
+
this.setAlert("danger", `<p> ${message} </p>`);
|
|
1486
1516
|
return Promise.reject(this.onSubmissionError(e));
|
|
1487
1517
|
});
|
|
1488
1518
|
}
|
|
1489
1519
|
else {
|
|
1490
|
-
this.emit(
|
|
1491
|
-
this.setAlert(
|
|
1492
|
-
return console.warn(
|
|
1520
|
+
this.emit("error", "You should add a URL to this button.");
|
|
1521
|
+
this.setAlert("warning", "You should add a URL to this button.");
|
|
1522
|
+
return console.warn("You should add a URL to this button.");
|
|
1493
1523
|
}
|
|
1494
1524
|
}
|
|
1495
1525
|
triggerCaptcha() {
|
|
@@ -1508,7 +1538,7 @@ export default class Webform extends NestedDataComponent {
|
|
|
1508
1538
|
}
|
|
1509
1539
|
set nosubmit(value) {
|
|
1510
1540
|
this._nosubmit = !!value;
|
|
1511
|
-
this.emit(
|
|
1541
|
+
this.emit("nosubmit", this._nosubmit);
|
|
1512
1542
|
}
|
|
1513
1543
|
get nosubmit() {
|
|
1514
1544
|
return this._nosubmit || false;
|