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