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