@formio/js 5.0.0-rc.27 → 5.0.0-rc.28
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/fonts/bootstrap-icons.woff +0 -0
- package/dist/fonts/bootstrap-icons.woff2 +0 -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 +710 -689
- package/dist/formio.form.min.js +1 -1
- package/dist/formio.form.min.js.LICENSE.txt +2 -2
- package/dist/formio.full.css +100 -3
- package/dist/formio.full.js +715 -727
- package/dist/formio.full.min.css +2 -2
- package/dist/formio.full.min.js +1 -1
- package/dist/formio.full.min.js.LICENSE.txt +2 -2
- package/dist/formio.js +659 -264
- package/dist/formio.min.js +1 -1
- package/dist/formio.min.js.LICENSE.txt +2 -2
- package/dist/formio.utils.js +29 -8
- package/dist/formio.utils.min.js +1 -1
- package/dist/formio.utils.min.js.LICENSE.txt +2 -2
- package/lib/cjs/Embed.d.ts +1 -1
- package/lib/cjs/Embed.js +14 -6
- package/lib/cjs/PDF.js +2 -2
- package/lib/cjs/Webform.d.ts +3 -5
- package/lib/cjs/Webform.js +59 -81
- package/lib/cjs/WebformBuilder.d.ts +1 -1
- package/lib/cjs/WebformBuilder.js +27 -10
- package/lib/cjs/Wizard.d.ts +2 -0
- package/lib/cjs/Wizard.js +37 -26
- package/lib/cjs/WizardBuilder.d.ts +1 -0
- package/lib/cjs/addons/PasswordStrength/PasswordStrengthAddon.d.ts +1 -2
- package/lib/cjs/addons/PasswordStrength/PasswordStrengthAddon.js +11 -12
- package/lib/cjs/addons/index.d.ts +1 -0
- package/lib/cjs/addons/index.js +5 -1
- package/lib/cjs/components/Components.d.ts +7 -0
- package/lib/cjs/components/Components.js +30 -0
- package/lib/cjs/components/_classes/component/Component.d.ts +57 -27
- package/lib/cjs/components/_classes/component/Component.js +193 -119
- package/lib/cjs/components/_classes/component/editForm/Component.edit.addons.d.ts +8 -0
- package/lib/cjs/components/_classes/component/editForm/Component.edit.addons.js +31 -1
- package/lib/cjs/components/_classes/nested/NestedComponent.d.ts +28 -11
- package/lib/cjs/components/_classes/nested/NestedComponent.js +88 -57
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +4 -3
- package/lib/cjs/components/_classes/nestedarray/NestedArrayComponent.js +17 -4
- package/lib/cjs/components/builder.js +0 -2
- package/lib/cjs/components/button/Button.js +2 -1
- package/lib/cjs/components/columns/Columns.d.ts +1 -0
- package/lib/cjs/components/columns/Columns.js +2 -3
- package/lib/cjs/components/columns/editForm/Columns.edit.display.d.ts +30 -1
- package/lib/cjs/components/columns/editForm/Columns.edit.display.js +23 -1
- package/lib/cjs/components/container/Container.d.ts +1 -0
- package/lib/cjs/components/container/Container.js +2 -6
- package/lib/cjs/components/content/Content.d.ts +1 -0
- package/lib/cjs/components/content/Content.js +1 -0
- package/lib/cjs/components/datagrid/DataGrid.d.ts +0 -8
- package/lib/cjs/components/datagrid/DataGrid.js +9 -26
- package/lib/cjs/components/datamap/DataMap.js +2 -1
- package/lib/cjs/components/datetime/DateTime.js +0 -2
- package/lib/cjs/components/day/Day.js +2 -3
- package/lib/cjs/components/editgrid/EditGrid.d.ts +8 -4
- package/lib/cjs/components/editgrid/EditGrid.js +96 -73
- package/lib/cjs/components/email/Email.js +0 -1
- package/lib/cjs/components/file/File.js +1 -1
- package/lib/cjs/components/file/fixtures/comp3.d.ts +29 -0
- package/lib/cjs/components/file/fixtures/comp3.js +31 -0
- package/lib/cjs/components/form/Form.d.ts +2 -6
- package/lib/cjs/components/form/Form.js +43 -14
- package/lib/cjs/components/index.d.ts +0 -2
- package/lib/cjs/components/index.js +0 -2
- package/lib/cjs/components/number/Number.d.ts +1 -2
- package/lib/cjs/components/number/Number.js +5 -6
- package/lib/cjs/components/panel/Panel.d.ts +0 -1
- package/lib/cjs/components/panel/Panel.js +2 -9
- package/lib/cjs/components/panel/editForm/Panel.edit.display.d.ts +6 -38
- package/lib/cjs/components/panel/editForm/Panel.edit.display.js +3 -16
- package/lib/cjs/components/phonenumber/PhoneNumber.js +17 -0
- package/lib/cjs/components/radio/Radio.js +0 -2
- package/lib/cjs/components/recaptcha/ReCaptcha.d.ts +1 -1
- package/lib/cjs/components/recaptcha/ReCaptcha.js +2 -2
- package/lib/cjs/components/select/Select.js +3 -2
- package/lib/cjs/components/selectboxes/SelectBoxes.d.ts +1 -2
- package/lib/cjs/components/selectboxes/SelectBoxes.js +7 -6
- package/lib/cjs/components/table/editForm/Table.edit.display.d.ts +31 -2
- package/lib/cjs/components/table/editForm/Table.edit.display.js +22 -0
- package/lib/cjs/components/tabs/editForm/Tabs.edit.display.d.ts +30 -2
- package/lib/cjs/components/tabs/editForm/Tabs.edit.display.js +22 -0
- package/lib/cjs/components/textfield/TextField.js +20 -6
- package/lib/cjs/components/time/Time.js +0 -6
- package/lib/cjs/components/url/Url.js +0 -1
- package/lib/cjs/components/well/editForm/Well.edit.display.d.ts +25 -2
- package/lib/cjs/components/well/editForm/Well.edit.display.js +18 -0
- package/lib/cjs/formio.embed.js +5 -3
- package/lib/cjs/formio.form.d.ts +1 -7
- package/lib/cjs/formio.form.js +2 -38
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/providers/Providers.d.ts +0 -4
- package/lib/cjs/providers/storage/azure.d.ts +0 -2
- package/lib/cjs/providers/storage/azure.js +1 -6
- package/lib/cjs/providers/storage/googleDrive.d.ts +0 -1
- package/lib/cjs/providers/storage/googleDrive.js +0 -4
- package/lib/cjs/providers/storage/s3.d.ts +0 -1
- package/lib/cjs/providers/storage/s3.js +0 -4
- package/lib/cjs/translations/en.d.ts +5 -0
- package/lib/cjs/translations/en.js +5 -0
- package/lib/cjs/utils/formUtils.js +1 -0
- package/lib/cjs/utils/utils.d.ts +2 -1
- package/lib/cjs/utils/utils.js +27 -9
- package/lib/mjs/Embed.d.ts +1 -1
- package/lib/mjs/Embed.js +14 -6
- package/lib/mjs/PDF.js +2 -2
- package/lib/mjs/Webform.d.ts +3 -5
- package/lib/mjs/Webform.js +58 -82
- package/lib/mjs/WebformBuilder.d.ts +1 -1
- package/lib/mjs/WebformBuilder.js +28 -7
- package/lib/mjs/Wizard.d.ts +2 -0
- package/lib/mjs/Wizard.js +36 -27
- package/lib/mjs/WizardBuilder.d.ts +1 -0
- package/lib/mjs/addons/PasswordStrength/PasswordStrengthAddon.d.ts +1 -2
- package/lib/mjs/addons/PasswordStrength/PasswordStrengthAddon.js +11 -12
- package/lib/mjs/addons/index.d.ts +1 -0
- package/lib/mjs/addons/index.js +5 -1
- package/lib/mjs/components/Components.d.ts +7 -0
- package/lib/mjs/components/Components.js +29 -0
- package/lib/mjs/components/_classes/component/Component.d.ts +57 -27
- package/lib/mjs/components/_classes/component/Component.js +191 -118
- package/lib/mjs/components/_classes/component/editForm/Component.edit.addons.d.ts +8 -0
- package/lib/mjs/components/_classes/component/editForm/Component.edit.addons.js +31 -1
- package/lib/mjs/components/_classes/nested/NestedComponent.d.ts +28 -11
- package/lib/mjs/components/_classes/nested/NestedComponent.js +88 -57
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.d.ts +4 -3
- package/lib/mjs/components/_classes/nestedarray/NestedArrayComponent.js +18 -5
- package/lib/mjs/components/builder.js +0 -2
- package/lib/mjs/components/button/Button.js +2 -1
- package/lib/mjs/components/columns/Columns.d.ts +1 -0
- package/lib/mjs/components/columns/Columns.js +2 -3
- package/lib/mjs/components/columns/editForm/Columns.edit.display.d.ts +30 -1
- package/lib/mjs/components/columns/editForm/Columns.edit.display.js +23 -1
- package/lib/mjs/components/container/Container.d.ts +1 -0
- package/lib/mjs/components/container/Container.js +2 -6
- package/lib/mjs/components/content/Content.d.ts +1 -0
- package/lib/mjs/components/content/Content.js +1 -0
- package/lib/mjs/components/datagrid/DataGrid.d.ts +0 -8
- package/lib/mjs/components/datagrid/DataGrid.js +9 -26
- package/lib/mjs/components/datamap/DataMap.js +2 -1
- package/lib/mjs/components/datetime/DateTime.js +0 -2
- package/lib/mjs/components/day/Day.js +2 -3
- package/lib/mjs/components/editgrid/EditGrid.d.ts +8 -4
- package/lib/mjs/components/editgrid/EditGrid.js +97 -76
- package/lib/mjs/components/email/Email.js +0 -1
- package/lib/mjs/components/file/File.js +1 -1
- package/lib/mjs/components/file/fixtures/comp3.d.ts +29 -0
- package/lib/mjs/components/file/fixtures/comp3.js +29 -0
- package/lib/mjs/components/form/Form.d.ts +2 -6
- package/lib/mjs/components/form/Form.js +45 -14
- package/lib/mjs/components/index.d.ts +0 -2
- package/lib/mjs/components/index.js +0 -2
- package/lib/mjs/components/number/Number.d.ts +1 -2
- package/lib/mjs/components/number/Number.js +4 -5
- package/lib/mjs/components/panel/Panel.d.ts +0 -1
- package/lib/mjs/components/panel/Panel.js +3 -9
- package/lib/mjs/components/panel/editForm/Panel.edit.display.d.ts +6 -38
- package/lib/mjs/components/panel/editForm/Panel.edit.display.js +3 -16
- package/lib/mjs/components/phonenumber/PhoneNumber.js +17 -0
- package/lib/mjs/components/radio/Radio.js +0 -2
- package/lib/mjs/components/recaptcha/ReCaptcha.d.ts +1 -1
- package/lib/mjs/components/recaptcha/ReCaptcha.js +2 -2
- package/lib/mjs/components/select/Select.js +3 -2
- package/lib/mjs/components/selectboxes/SelectBoxes.d.ts +1 -2
- package/lib/mjs/components/selectboxes/SelectBoxes.js +7 -6
- package/lib/mjs/components/table/editForm/Table.edit.display.d.ts +31 -2
- package/lib/mjs/components/table/editForm/Table.edit.display.js +22 -0
- package/lib/mjs/components/tabs/editForm/Tabs.edit.display.d.ts +30 -2
- package/lib/mjs/components/tabs/editForm/Tabs.edit.display.js +22 -0
- package/lib/mjs/components/textfield/TextField.js +20 -6
- package/lib/mjs/components/time/Time.js +0 -6
- package/lib/mjs/components/url/Url.js +0 -1
- package/lib/mjs/components/well/editForm/Well.edit.display.d.ts +25 -2
- package/lib/mjs/components/well/editForm/Well.edit.display.js +18 -0
- package/lib/mjs/formio.embed.js +5 -3
- package/lib/mjs/formio.form.d.ts +1 -7
- package/lib/mjs/formio.form.js +2 -32
- package/lib/mjs/index.d.ts +2 -1
- package/lib/mjs/index.js +1 -1
- package/lib/mjs/providers/Providers.d.ts +0 -4
- package/lib/mjs/providers/storage/azure.d.ts +0 -2
- package/lib/mjs/providers/storage/azure.js +1 -6
- package/lib/mjs/providers/storage/googleDrive.d.ts +0 -1
- package/lib/mjs/providers/storage/googleDrive.js +0 -4
- package/lib/mjs/providers/storage/s3.d.ts +0 -1
- package/lib/mjs/providers/storage/s3.js +0 -4
- package/lib/mjs/translations/en.d.ts +5 -0
- package/lib/mjs/translations/en.js +5 -0
- package/lib/mjs/utils/formUtils.js +1 -0
- package/lib/mjs/utils/utils.d.ts +2 -1
- package/lib/mjs/utils/utils.js +24 -7
- package/package.json +5 -5
- package/lib/cjs/components/tree/Node.d.ts +0 -55
- package/lib/cjs/components/tree/Node.js +0 -185
- package/lib/cjs/components/tree/Tree.d.ts +0 -48
- package/lib/cjs/components/tree/Tree.form.d.ts +0 -3
- package/lib/cjs/components/tree/Tree.form.js +0 -21
- package/lib/cjs/components/tree/Tree.js +0 -383
- package/lib/cjs/components/tree/editForm/Tree.edit.data.d.ts +0 -5
- package/lib/cjs/components/tree/editForm/Tree.edit.data.js +0 -9
- package/lib/cjs/components/tree/editForm/Tree.edit.display.d.ts +0 -9
- package/lib/cjs/components/tree/editForm/Tree.edit.display.js +0 -12
- package/lib/cjs/components/tree/fixtures/comp1.d.ts +0 -23
- package/lib/cjs/components/tree/fixtures/comp1.js +0 -24
- package/lib/cjs/components/tree/fixtures/comp2.d.ts +0 -116
- package/lib/cjs/components/tree/fixtures/comp2.js +0 -82
- package/lib/cjs/components/tree/fixtures/comp3.d.ts +0 -24
- package/lib/cjs/components/tree/fixtures/comp3.js +0 -25
- package/lib/cjs/components/tree/fixtures/comp4.d.ts +0 -42
- package/lib/cjs/components/tree/fixtures/comp4.js +0 -47
- package/lib/cjs/components/tree/fixtures/index.d.ts +0 -5
- package/lib/cjs/components/tree/fixtures/index.js +0 -14
- package/lib/cjs/validator/Rules.d.ts +0 -53
- package/lib/cjs/validator/Rules.js +0 -22
- package/lib/cjs/validator/Validator.d.ts +0 -228
- package/lib/cjs/validator/Validator.js +0 -1113
- package/lib/cjs/validator/conjunctions/index.d.ts +0 -7
- package/lib/cjs/validator/conjunctions/index.js +0 -18
- package/lib/cjs/validator/operators/index.d.ts +0 -7
- package/lib/cjs/validator/operators/index.js +0 -18
- package/lib/cjs/validator/quickRules/index.d.ts +0 -7
- package/lib/cjs/validator/quickRules/index.js +0 -18
- package/lib/cjs/validator/rules/Custom.d.ts +0 -5
- package/lib/cjs/validator/rules/Custom.js +0 -30
- package/lib/cjs/validator/rules/Date.d.ts +0 -5
- package/lib/cjs/validator/rules/Date.js +0 -25
- package/lib/cjs/validator/rules/Day.d.ts +0 -5
- package/lib/cjs/validator/rules/Day.js +0 -58
- package/lib/cjs/validator/rules/Email.d.ts +0 -5
- package/lib/cjs/validator/rules/Email.js +0 -24
- package/lib/cjs/validator/rules/JSON.d.ts +0 -5
- package/lib/cjs/validator/rules/JSON.js +0 -29
- package/lib/cjs/validator/rules/Mask.d.ts +0 -5
- package/lib/cjs/validator/rules/Mask.js +0 -32
- package/lib/cjs/validator/rules/Max.d.ts +0 -5
- package/lib/cjs/validator/rules/Max.js +0 -21
- package/lib/cjs/validator/rules/MaxDate.d.ts +0 -5
- package/lib/cjs/validator/rules/MaxDate.js +0 -34
- package/lib/cjs/validator/rules/MaxLength.d.ts +0 -5
- package/lib/cjs/validator/rules/MaxLength.js +0 -20
- package/lib/cjs/validator/rules/MaxWords.d.ts +0 -5
- package/lib/cjs/validator/rules/MaxWords.js +0 -20
- package/lib/cjs/validator/rules/MaxYear.d.ts +0 -5
- package/lib/cjs/validator/rules/MaxYear.js +0 -22
- package/lib/cjs/validator/rules/Min.d.ts +0 -5
- package/lib/cjs/validator/rules/Min.js +0 -21
- package/lib/cjs/validator/rules/MinDate.d.ts +0 -5
- package/lib/cjs/validator/rules/MinDate.js +0 -30
- package/lib/cjs/validator/rules/MinLength.d.ts +0 -5
- package/lib/cjs/validator/rules/MinLength.js +0 -20
- package/lib/cjs/validator/rules/MinWords.d.ts +0 -5
- package/lib/cjs/validator/rules/MinWords.js +0 -20
- package/lib/cjs/validator/rules/MinYear.d.ts +0 -5
- package/lib/cjs/validator/rules/MinYear.js +0 -22
- package/lib/cjs/validator/rules/Pattern.d.ts +0 -5
- package/lib/cjs/validator/rules/Pattern.js +0 -20
- package/lib/cjs/validator/rules/Required.d.ts +0 -5
- package/lib/cjs/validator/rules/Required.js +0 -17
- package/lib/cjs/validator/rules/Rule.d.ts +0 -7
- package/lib/cjs/validator/rules/Rule.js +0 -12
- package/lib/cjs/validator/rules/Select.d.ts +0 -5
- package/lib/cjs/validator/rules/Select.js +0 -95
- package/lib/cjs/validator/rules/Time.d.ts +0 -5
- package/lib/cjs/validator/rules/Time.js +0 -19
- package/lib/cjs/validator/rules/Unique.d.ts +0 -5
- package/lib/cjs/validator/rules/Unique.js +0 -69
- package/lib/cjs/validator/rules/Url.d.ts +0 -5
- package/lib/cjs/validator/rules/Url.js +0 -23
- package/lib/cjs/validator/rules/index.d.ts +0 -47
- package/lib/cjs/validator/rules/index.js +0 -51
- package/lib/cjs/validator/transformers/index.d.ts +0 -7
- package/lib/cjs/validator/transformers/index.js +0 -18
- package/lib/cjs/validator/valueSources/index.d.ts +0 -7
- package/lib/cjs/validator/valueSources/index.js +0 -18
- package/lib/mjs/components/tree/Node.d.ts +0 -55
- package/lib/mjs/components/tree/Node.js +0 -179
- package/lib/mjs/components/tree/Tree.d.ts +0 -48
- package/lib/mjs/components/tree/Tree.form.d.ts +0 -3
- package/lib/mjs/components/tree/Tree.form.js +0 -15
- package/lib/mjs/components/tree/Tree.js +0 -384
- package/lib/mjs/components/tree/editForm/Tree.edit.data.d.ts +0 -5
- package/lib/mjs/components/tree/editForm/Tree.edit.data.js +0 -7
- package/lib/mjs/components/tree/editForm/Tree.edit.display.d.ts +0 -9
- package/lib/mjs/components/tree/editForm/Tree.edit.display.js +0 -10
- package/lib/mjs/components/tree/fixtures/comp1.d.ts +0 -23
- package/lib/mjs/components/tree/fixtures/comp1.js +0 -22
- package/lib/mjs/components/tree/fixtures/comp2.d.ts +0 -116
- package/lib/mjs/components/tree/fixtures/comp2.js +0 -80
- package/lib/mjs/components/tree/fixtures/comp3.d.ts +0 -24
- package/lib/mjs/components/tree/fixtures/comp3.js +0 -23
- package/lib/mjs/components/tree/fixtures/comp4.d.ts +0 -42
- package/lib/mjs/components/tree/fixtures/comp4.js +0 -45
- package/lib/mjs/components/tree/fixtures/index.d.ts +0 -5
- package/lib/mjs/components/tree/fixtures/index.js +0 -5
- package/lib/mjs/validator/Rules.d.ts +0 -53
- package/lib/mjs/validator/Rules.js +0 -17
- package/lib/mjs/validator/Validator.d.ts +0 -228
- package/lib/mjs/validator/Validator.js +0 -1103
- package/lib/mjs/validator/conjunctions/index.d.ts +0 -7
- package/lib/mjs/validator/conjunctions/index.js +0 -16
- package/lib/mjs/validator/operators/index.d.ts +0 -7
- package/lib/mjs/validator/operators/index.js +0 -16
- package/lib/mjs/validator/quickRules/index.d.ts +0 -7
- package/lib/mjs/validator/quickRules/index.js +0 -16
- package/lib/mjs/validator/rules/Custom.d.ts +0 -5
- package/lib/mjs/validator/rules/Custom.js +0 -21
- package/lib/mjs/validator/rules/Date.d.ts +0 -5
- package/lib/mjs/validator/rules/Date.js +0 -16
- package/lib/mjs/validator/rules/Day.d.ts +0 -5
- package/lib/mjs/validator/rules/Day.js +0 -49
- package/lib/mjs/validator/rules/Email.d.ts +0 -5
- package/lib/mjs/validator/rules/Email.js +0 -15
- package/lib/mjs/validator/rules/JSON.d.ts +0 -5
- package/lib/mjs/validator/rules/JSON.js +0 -20
- package/lib/mjs/validator/rules/Mask.d.ts +0 -5
- package/lib/mjs/validator/rules/Mask.js +0 -23
- package/lib/mjs/validator/rules/Max.d.ts +0 -5
- package/lib/mjs/validator/rules/Max.js +0 -12
- package/lib/mjs/validator/rules/MaxDate.d.ts +0 -5
- package/lib/mjs/validator/rules/MaxDate.js +0 -25
- package/lib/mjs/validator/rules/MaxLength.d.ts +0 -5
- package/lib/mjs/validator/rules/MaxLength.js +0 -11
- package/lib/mjs/validator/rules/MaxWords.d.ts +0 -5
- package/lib/mjs/validator/rules/MaxWords.js +0 -11
- package/lib/mjs/validator/rules/MaxYear.d.ts +0 -5
- package/lib/mjs/validator/rules/MaxYear.js +0 -13
- package/lib/mjs/validator/rules/Min.d.ts +0 -5
- package/lib/mjs/validator/rules/Min.js +0 -12
- package/lib/mjs/validator/rules/MinDate.d.ts +0 -5
- package/lib/mjs/validator/rules/MinDate.js +0 -21
- package/lib/mjs/validator/rules/MinLength.d.ts +0 -5
- package/lib/mjs/validator/rules/MinLength.js +0 -11
- package/lib/mjs/validator/rules/MinWords.d.ts +0 -5
- package/lib/mjs/validator/rules/MinWords.js +0 -11
- package/lib/mjs/validator/rules/MinYear.d.ts +0 -5
- package/lib/mjs/validator/rules/MinYear.js +0 -13
- package/lib/mjs/validator/rules/Pattern.d.ts +0 -5
- package/lib/mjs/validator/rules/Pattern.js +0 -11
- package/lib/mjs/validator/rules/Required.d.ts +0 -5
- package/lib/mjs/validator/rules/Required.js +0 -8
- package/lib/mjs/validator/rules/Rule.d.ts +0 -7
- package/lib/mjs/validator/rules/Rule.js +0 -9
- package/lib/mjs/validator/rules/Select.d.ts +0 -5
- package/lib/mjs/validator/rules/Select.js +0 -86
- package/lib/mjs/validator/rules/Time.d.ts +0 -5
- package/lib/mjs/validator/rules/Time.js +0 -10
- package/lib/mjs/validator/rules/Unique.d.ts +0 -5
- package/lib/mjs/validator/rules/Unique.js +0 -60
- package/lib/mjs/validator/rules/Url.d.ts +0 -5
- package/lib/mjs/validator/rules/Url.js +0 -14
- package/lib/mjs/validator/rules/index.d.ts +0 -47
- package/lib/mjs/validator/rules/index.js +0 -46
- package/lib/mjs/validator/transformers/index.d.ts +0 -7
- package/lib/mjs/validator/transformers/index.js +0 -16
- package/lib/mjs/validator/valueSources/index.d.ts +0 -7
- package/lib/mjs/validator/valueSources/index.js +0 -16
@@ -1,1103 +0,0 @@
|
|
1
|
-
import _ from 'lodash';
|
2
|
-
import { boolValue, getInputMask, matchInputMask, getDateSetting, escapeRegExCharacters, interpolate, convertFormatToMoment, getArrayFromComponentPath, unescapeHTML } from '../utils/utils';
|
3
|
-
import moment from 'moment';
|
4
|
-
import fetchPonyfill from 'fetch-ponyfill';
|
5
|
-
const { fetch, Headers, Request } = fetchPonyfill({
|
6
|
-
Promise: Promise
|
7
|
-
});
|
8
|
-
import { checkInvalidDate, CALENDAR_ERROR_MESSAGES } from '../utils/calendarUtils';
|
9
|
-
import Rules from './Rules';
|
10
|
-
class ValidationChecker {
|
11
|
-
constructor(config = {}) {
|
12
|
-
this.config = _.defaults(config, ValidationChecker.config);
|
13
|
-
this.validators = {
|
14
|
-
required: {
|
15
|
-
key: 'validate.required',
|
16
|
-
method: 'validateRequired',
|
17
|
-
hasLabel: true,
|
18
|
-
message(component) {
|
19
|
-
return component.t(component.errorMessage('required'), {
|
20
|
-
field: component.errorLabel,
|
21
|
-
data: component.data
|
22
|
-
});
|
23
|
-
},
|
24
|
-
check(component, setting, value) {
|
25
|
-
if (!boolValue(setting) || component.isValueHidden()) {
|
26
|
-
return true;
|
27
|
-
}
|
28
|
-
const isCalendar = component.validators.some(validator => validator === 'calendar');
|
29
|
-
if (!value && isCalendar && component.widget.enteredDate) {
|
30
|
-
return !this.validators.calendar.check.call(this, component, setting, value);
|
31
|
-
}
|
32
|
-
return !component.isEmpty(value);
|
33
|
-
}
|
34
|
-
},
|
35
|
-
onlyAvailableItems: {
|
36
|
-
key: 'validate.onlyAvailableItems',
|
37
|
-
method: 'validateValueAvailability',
|
38
|
-
hasLabel: true,
|
39
|
-
message(component) {
|
40
|
-
return component.t(component.errorMessage('valueIsNotAvailable'), {
|
41
|
-
field: component.errorLabel,
|
42
|
-
data: component.data
|
43
|
-
});
|
44
|
-
},
|
45
|
-
check(component, setting) {
|
46
|
-
return !boolValue(setting);
|
47
|
-
}
|
48
|
-
},
|
49
|
-
unique: {
|
50
|
-
key: 'validate.unique',
|
51
|
-
hasLabel: true,
|
52
|
-
message(component) {
|
53
|
-
return component.t(component.errorMessage('unique'), {
|
54
|
-
field: component.errorLabel,
|
55
|
-
data: component.data
|
56
|
-
});
|
57
|
-
},
|
58
|
-
check(component, setting, value) {
|
59
|
-
// Skip if setting is falsy
|
60
|
-
if (!boolValue(setting)) {
|
61
|
-
return true;
|
62
|
-
}
|
63
|
-
// Skip if value is empty object or falsy
|
64
|
-
if (!value || _.isObjectLike(value) && _.isEmpty(value)) {
|
65
|
-
return true;
|
66
|
-
}
|
67
|
-
// Skip if we don't have a database connection
|
68
|
-
if (!this.config.db) {
|
69
|
-
return true;
|
70
|
-
}
|
71
|
-
return new Promise(resolve => {
|
72
|
-
const form = this.config.form;
|
73
|
-
const submission = this.config.submission;
|
74
|
-
const path = `data.${component.path}`;
|
75
|
-
const addPathQueryParams = (pathQueryParams, query, path) => {
|
76
|
-
const pathArray = path.split(/\[\d+\]?./);
|
77
|
-
const needValuesInArray = pathArray.length > 1;
|
78
|
-
let pathToValue = path;
|
79
|
-
if (needValuesInArray) {
|
80
|
-
pathToValue = pathArray.shift();
|
81
|
-
const pathQueryObj = {};
|
82
|
-
_.reduce(pathArray, (pathQueryPath, pathPart, index) => {
|
83
|
-
const isLastPathPart = index === (pathArray.length - 1);
|
84
|
-
const obj = _.get(pathQueryObj, pathQueryPath, pathQueryObj);
|
85
|
-
const addedPath = `$elemMatch['${pathPart}']`;
|
86
|
-
_.set(obj, addedPath, isLastPathPart ? pathQueryParams : {});
|
87
|
-
return pathQueryPath ? `${pathQueryPath}.${addedPath}` : addedPath;
|
88
|
-
}, '');
|
89
|
-
query[pathToValue] = pathQueryObj;
|
90
|
-
}
|
91
|
-
else {
|
92
|
-
query[pathToValue] = pathQueryParams;
|
93
|
-
}
|
94
|
-
};
|
95
|
-
// Build the query
|
96
|
-
const query = { form: form._id };
|
97
|
-
let collationOptions = {};
|
98
|
-
if (_.isString(value)) {
|
99
|
-
if (component.component.dbIndex) {
|
100
|
-
addPathQueryParams(value, query, path);
|
101
|
-
}
|
102
|
-
// These are kind of hacky but provides for a more efficient "unique" validation when the string is an email,
|
103
|
-
// because we (by and large) only have to worry about ASCII and partial unicode; this way, we can use collation-
|
104
|
-
// aware indexes with case insensitive email searches to make things like login and registration a whole lot faster
|
105
|
-
else if (component.component.type === 'email' ||
|
106
|
-
(component.component.type === 'textfield' && component.component.validate?.pattern === '[A-Za-z0-9]+')) {
|
107
|
-
addPathQueryParams(value, query, path);
|
108
|
-
collationOptions = { collation: { locale: 'en', strength: 2 } };
|
109
|
-
}
|
110
|
-
else {
|
111
|
-
addPathQueryParams({
|
112
|
-
$regex: new RegExp(`^${escapeRegExCharacters(value)}$`),
|
113
|
-
$options: 'i'
|
114
|
-
}, query, path);
|
115
|
-
}
|
116
|
-
}
|
117
|
-
// FOR-213 - Pluck the unique location id
|
118
|
-
else if (_.isPlainObject(value) &&
|
119
|
-
value.address &&
|
120
|
-
value.address['address_components'] &&
|
121
|
-
value.address['place_id']) {
|
122
|
-
addPathQueryParams({
|
123
|
-
$regex: new RegExp(`^${escapeRegExCharacters(value.address['place_id'])}$`),
|
124
|
-
$options: 'i'
|
125
|
-
}, query, `${path}.address.place_id`);
|
126
|
-
}
|
127
|
-
// Compare the contents of arrays vs the order.
|
128
|
-
else if (_.isArray(value)) {
|
129
|
-
addPathQueryParams({ $all: value }, query, path);
|
130
|
-
}
|
131
|
-
else if (_.isObject(value) || _.isNumber(value)) {
|
132
|
-
addPathQueryParams({ $eq: value }, query, path);
|
133
|
-
}
|
134
|
-
// Only search for non-deleted items
|
135
|
-
query.deleted = { $eq: null };
|
136
|
-
query.state = 'submitted';
|
137
|
-
const uniqueValidationCallback = (err, result) => {
|
138
|
-
if (err) {
|
139
|
-
return resolve(false);
|
140
|
-
}
|
141
|
-
else if (result) {
|
142
|
-
// Only OK if it matches the current submission
|
143
|
-
if (submission._id && (result._id.toString() === submission._id)) {
|
144
|
-
resolve(true);
|
145
|
-
}
|
146
|
-
else {
|
147
|
-
component.conflictId = result._id.toString();
|
148
|
-
return resolve(false);
|
149
|
-
}
|
150
|
-
}
|
151
|
-
else {
|
152
|
-
return resolve(true);
|
153
|
-
}
|
154
|
-
};
|
155
|
-
// Try to find an existing value within the form
|
156
|
-
this.config.db.findOne(query, null, collationOptions, (err, result) => {
|
157
|
-
if (err && collationOptions.collation) {
|
158
|
-
// presume this error comes from db compatibility, try again as regex
|
159
|
-
delete query[path];
|
160
|
-
addPathQueryParams({
|
161
|
-
$regex: new RegExp(`^${escapeRegExCharacters(value)}$`),
|
162
|
-
$options: 'i'
|
163
|
-
}, query, path);
|
164
|
-
this.config.db.findOne(query, uniqueValidationCallback);
|
165
|
-
}
|
166
|
-
else {
|
167
|
-
return uniqueValidationCallback(err, result);
|
168
|
-
}
|
169
|
-
});
|
170
|
-
}).catch(() => false);
|
171
|
-
}
|
172
|
-
},
|
173
|
-
multiple: {
|
174
|
-
key: 'validate.multiple',
|
175
|
-
hasLabel: true,
|
176
|
-
message(component) {
|
177
|
-
const shouldBeArray = boolValue(component.component.multiple) || Array.isArray(component.emptyValue);
|
178
|
-
const isRequired = component.component.validate.required;
|
179
|
-
const messageKey = shouldBeArray ? (isRequired ? 'array_nonempty' : 'array') : 'nonarray';
|
180
|
-
return component.t(component.errorMessage(messageKey), {
|
181
|
-
field: component.errorLabel,
|
182
|
-
data: component.data
|
183
|
-
});
|
184
|
-
},
|
185
|
-
check(component, setting, value) {
|
186
|
-
// Skip multiple validation if the component tells us to
|
187
|
-
if (!component.validateMultiple()) {
|
188
|
-
return true;
|
189
|
-
}
|
190
|
-
const shouldBeArray = boolValue(setting);
|
191
|
-
const canBeArray = Array.isArray(component.emptyValue);
|
192
|
-
const isArray = Array.isArray(value);
|
193
|
-
const isRequired = component.component.validate.required;
|
194
|
-
if (shouldBeArray) {
|
195
|
-
if (isArray) {
|
196
|
-
return isRequired ? !!value.length : true;
|
197
|
-
}
|
198
|
-
else {
|
199
|
-
// Null/undefined is ok if this value isn't required; anything else should fail
|
200
|
-
return _.isNil(value) ? !isRequired : false;
|
201
|
-
}
|
202
|
-
}
|
203
|
-
else {
|
204
|
-
return canBeArray || !isArray;
|
205
|
-
}
|
206
|
-
}
|
207
|
-
},
|
208
|
-
select: {
|
209
|
-
key: 'validate.select',
|
210
|
-
hasLabel: true,
|
211
|
-
message(component) {
|
212
|
-
return component.t(component.errorMessage('select'), {
|
213
|
-
field: component.errorLabel,
|
214
|
-
data: component.data
|
215
|
-
});
|
216
|
-
},
|
217
|
-
check(component, setting, value, data, index, row, async) {
|
218
|
-
// Skip if setting is falsy
|
219
|
-
if (!boolValue(setting)) {
|
220
|
-
return true;
|
221
|
-
}
|
222
|
-
// Skip if value is empty
|
223
|
-
if (!value || _.isEmpty(value)) {
|
224
|
-
return true;
|
225
|
-
}
|
226
|
-
// Skip if we're not async-capable
|
227
|
-
if (!async) {
|
228
|
-
return true;
|
229
|
-
}
|
230
|
-
const schema = component.component;
|
231
|
-
// Initialize the request options
|
232
|
-
const requestOptions = {
|
233
|
-
url: setting,
|
234
|
-
method: 'GET',
|
235
|
-
qs: {},
|
236
|
-
json: true,
|
237
|
-
headers: {}
|
238
|
-
};
|
239
|
-
// If the url is a boolean value
|
240
|
-
if (_.isBoolean(requestOptions.url)) {
|
241
|
-
requestOptions.url = !!requestOptions.url;
|
242
|
-
if (!requestOptions.url ||
|
243
|
-
schema.dataSrc !== 'url' ||
|
244
|
-
!schema.data.url ||
|
245
|
-
!schema.searchField) {
|
246
|
-
return true;
|
247
|
-
}
|
248
|
-
// Get the validation url
|
249
|
-
requestOptions.url = schema.data.url;
|
250
|
-
// Add the search field
|
251
|
-
requestOptions.qs[schema.searchField] = value;
|
252
|
-
// Add the filters
|
253
|
-
if (schema.filter) {
|
254
|
-
requestOptions.url += (!requestOptions.url.includes('?') ? '?' : '&') + schema.filter;
|
255
|
-
}
|
256
|
-
// If they only wish to return certain fields.
|
257
|
-
if (schema.selectFields) {
|
258
|
-
requestOptions.qs.select = schema.selectFields;
|
259
|
-
}
|
260
|
-
}
|
261
|
-
if (!requestOptions.url) {
|
262
|
-
return true;
|
263
|
-
}
|
264
|
-
// Make sure to interpolate.
|
265
|
-
requestOptions.url = interpolate(requestOptions.url, { data: component.data });
|
266
|
-
// Add query string to URL
|
267
|
-
requestOptions.url += (requestOptions.url.includes('?') ? '&' : '?') + _.chain(requestOptions.qs)
|
268
|
-
.map((val, key) => `${encodeURIComponent(key)}=${encodeURIComponent(val)}`)
|
269
|
-
.join('&')
|
270
|
-
.value();
|
271
|
-
// Set custom headers.
|
272
|
-
if (schema.data && schema.data.headers) {
|
273
|
-
_.each(schema.data.headers, header => {
|
274
|
-
if (header.key) {
|
275
|
-
requestOptions.headers[header.key] = header.value;
|
276
|
-
}
|
277
|
-
});
|
278
|
-
}
|
279
|
-
// Set form.io authentication.
|
280
|
-
if (schema.authenticate && this.config.token) {
|
281
|
-
requestOptions.headers['x-jwt-token'] = this.config.token;
|
282
|
-
}
|
283
|
-
return fetch(new Request(requestOptions.url, {
|
284
|
-
headers: new Headers(requestOptions.headers)
|
285
|
-
}))
|
286
|
-
.then(response => {
|
287
|
-
if (!response.ok) {
|
288
|
-
return false;
|
289
|
-
}
|
290
|
-
return response.json();
|
291
|
-
})
|
292
|
-
.then((results) => {
|
293
|
-
return results && results.length;
|
294
|
-
})
|
295
|
-
.catch(() => false);
|
296
|
-
}
|
297
|
-
},
|
298
|
-
min: {
|
299
|
-
key: 'validate.min',
|
300
|
-
hasLabel: true,
|
301
|
-
message(component, setting) {
|
302
|
-
return component.t(component.errorMessage('min'), {
|
303
|
-
field: component.errorLabel,
|
304
|
-
min: parseFloat(setting),
|
305
|
-
data: component.data
|
306
|
-
});
|
307
|
-
},
|
308
|
-
check(component, setting, value) {
|
309
|
-
const min = parseFloat(setting);
|
310
|
-
const parsedValue = parseFloat(value);
|
311
|
-
if (Number.isNaN(min) || Number.isNaN(parsedValue)) {
|
312
|
-
return true;
|
313
|
-
}
|
314
|
-
return parsedValue >= min;
|
315
|
-
}
|
316
|
-
},
|
317
|
-
max: {
|
318
|
-
key: 'validate.max',
|
319
|
-
hasLabel: true,
|
320
|
-
message(component, setting) {
|
321
|
-
return component.t(component.errorMessage('max'), {
|
322
|
-
field: component.errorLabel,
|
323
|
-
max: parseFloat(setting),
|
324
|
-
data: component.data
|
325
|
-
});
|
326
|
-
},
|
327
|
-
check(component, setting, value) {
|
328
|
-
const max = parseFloat(setting);
|
329
|
-
const parsedValue = parseFloat(value);
|
330
|
-
if (Number.isNaN(max) || Number.isNaN(parsedValue)) {
|
331
|
-
return true;
|
332
|
-
}
|
333
|
-
return parsedValue <= max;
|
334
|
-
}
|
335
|
-
},
|
336
|
-
minSelectedCount: {
|
337
|
-
key: 'validate.minSelectedCount',
|
338
|
-
message(component, setting) {
|
339
|
-
return component.component.minSelectedCountMessage
|
340
|
-
? component.component.minSelectedCountMessage
|
341
|
-
: component.t(component.errorMessage('minSelectedCount'), {
|
342
|
-
minCount: parseFloat(setting),
|
343
|
-
data: component.data
|
344
|
-
});
|
345
|
-
},
|
346
|
-
check(component, setting, value) {
|
347
|
-
const min = parseFloat(setting);
|
348
|
-
if (!min) {
|
349
|
-
return true;
|
350
|
-
}
|
351
|
-
const count = Object.keys(value).reduce((total, key) => {
|
352
|
-
if (value[key]) {
|
353
|
-
total++;
|
354
|
-
}
|
355
|
-
return total;
|
356
|
-
}, 0);
|
357
|
-
// Should not be triggered if there is no options selected at all
|
358
|
-
return !count || count >= min;
|
359
|
-
}
|
360
|
-
},
|
361
|
-
maxSelectedCount: {
|
362
|
-
key: 'validate.maxSelectedCount',
|
363
|
-
message(component, setting) {
|
364
|
-
return component.component.maxSelectedCountMessage
|
365
|
-
? component.component.maxSelectedCountMessage
|
366
|
-
: component.t(component.errorMessage('maxSelectedCount'), {
|
367
|
-
minCount: parseFloat(setting),
|
368
|
-
data: component.data
|
369
|
-
});
|
370
|
-
},
|
371
|
-
check(component, setting, value) {
|
372
|
-
const max = parseFloat(setting);
|
373
|
-
if (!max) {
|
374
|
-
return true;
|
375
|
-
}
|
376
|
-
const count = Object.keys(value).reduce((total, key) => {
|
377
|
-
if (value[key]) {
|
378
|
-
total++;
|
379
|
-
}
|
380
|
-
return total;
|
381
|
-
}, 0);
|
382
|
-
return count <= max;
|
383
|
-
}
|
384
|
-
},
|
385
|
-
minLength: {
|
386
|
-
key: 'validate.minLength',
|
387
|
-
hasLabel: true,
|
388
|
-
message(component, setting) {
|
389
|
-
return component.t(component.errorMessage('minLength'), {
|
390
|
-
field: component.errorLabel,
|
391
|
-
length: setting,
|
392
|
-
data: component.data
|
393
|
-
});
|
394
|
-
},
|
395
|
-
check(component, setting, value) {
|
396
|
-
const minLength = parseInt(setting, 10);
|
397
|
-
if (!value || !minLength || (typeof value !== 'string') || component.isEmpty(value)) {
|
398
|
-
return true;
|
399
|
-
}
|
400
|
-
return (value.length >= minLength);
|
401
|
-
}
|
402
|
-
},
|
403
|
-
maxLength: {
|
404
|
-
key: 'validate.maxLength',
|
405
|
-
hasLabel: true,
|
406
|
-
message(component, setting) {
|
407
|
-
return component.t(component.errorMessage('maxLength'), {
|
408
|
-
field: component.errorLabel,
|
409
|
-
length: setting,
|
410
|
-
data: component.data
|
411
|
-
});
|
412
|
-
},
|
413
|
-
check(component, setting, value) {
|
414
|
-
const maxLength = parseInt(setting, 10);
|
415
|
-
if (!maxLength || (typeof value !== 'string')) {
|
416
|
-
return true;
|
417
|
-
}
|
418
|
-
return (value.length <= maxLength);
|
419
|
-
}
|
420
|
-
},
|
421
|
-
maxWords: {
|
422
|
-
key: 'validate.maxWords',
|
423
|
-
hasLabel: true,
|
424
|
-
message(component, setting) {
|
425
|
-
return component.t(component.errorMessage('maxWords'), {
|
426
|
-
field: component.errorLabel,
|
427
|
-
length: setting,
|
428
|
-
data: component.data
|
429
|
-
});
|
430
|
-
},
|
431
|
-
check(component, setting, value) {
|
432
|
-
const maxWords = parseInt(setting, 10);
|
433
|
-
if (!maxWords || (typeof value !== 'string')) {
|
434
|
-
return true;
|
435
|
-
}
|
436
|
-
return (value.trim().split(/\s+/).length <= maxWords);
|
437
|
-
}
|
438
|
-
},
|
439
|
-
minWords: {
|
440
|
-
key: 'validate.minWords',
|
441
|
-
hasLabel: true,
|
442
|
-
message(component, setting) {
|
443
|
-
return component.t(component.errorMessage('minWords'), {
|
444
|
-
field: component.errorLabel,
|
445
|
-
length: setting,
|
446
|
-
data: component.data
|
447
|
-
});
|
448
|
-
},
|
449
|
-
check(component, setting, value) {
|
450
|
-
const minWords = parseInt(setting, 10);
|
451
|
-
if (!minWords || !value || (typeof value !== 'string')) {
|
452
|
-
return true;
|
453
|
-
}
|
454
|
-
return (value.trim().split(/\s+/).length >= minWords);
|
455
|
-
}
|
456
|
-
},
|
457
|
-
email: {
|
458
|
-
hasLabel: true,
|
459
|
-
message(component) {
|
460
|
-
return component.t(component.errorMessage('invalid_email'), {
|
461
|
-
field: component.errorLabel,
|
462
|
-
data: component.data
|
463
|
-
});
|
464
|
-
},
|
465
|
-
check(component, setting, value) {
|
466
|
-
/* eslint-disable max-len */
|
467
|
-
// From http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
|
468
|
-
const re = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
469
|
-
/* eslint-enable max-len */
|
470
|
-
// Allow emails to be valid if the component is pristine and no value is provided.
|
471
|
-
return !value || re.test(value);
|
472
|
-
}
|
473
|
-
},
|
474
|
-
url: {
|
475
|
-
hasLabel: true,
|
476
|
-
message(component) {
|
477
|
-
return component.t(component.errorMessage('invalid_url'), {
|
478
|
-
field: component.errorLabel,
|
479
|
-
data: component.data
|
480
|
-
});
|
481
|
-
},
|
482
|
-
check(component, setting, value) {
|
483
|
-
/* eslint-disable max-len */
|
484
|
-
// From https://stackoverflow.com/questions/8667070/javascript-regular-expression-to-validate-url
|
485
|
-
const re = /^(?:(?:(?:https?|ftp):)?\/\/)?(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;
|
486
|
-
// From http://stackoverflow.com/questions/46155/validate-email-address-in-javascript
|
487
|
-
const emailRe = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
488
|
-
/* eslint-enable max-len */
|
489
|
-
// Allow urls to be valid if the component is pristine and no value is provided.
|
490
|
-
return !value || (re.test(value) && !emailRe.test(value));
|
491
|
-
}
|
492
|
-
},
|
493
|
-
date: {
|
494
|
-
hasLabel: true,
|
495
|
-
message(component) {
|
496
|
-
return component.t(component.errorMessage('invalid_date'), {
|
497
|
-
field: component.errorLabel,
|
498
|
-
data: component.data
|
499
|
-
});
|
500
|
-
},
|
501
|
-
check(component, setting, value) {
|
502
|
-
if (!value) {
|
503
|
-
return true;
|
504
|
-
}
|
505
|
-
if (value === 'Invalid date' || value === 'Invalid Date') {
|
506
|
-
return false;
|
507
|
-
}
|
508
|
-
if (typeof value === 'string') {
|
509
|
-
value = new Date(value);
|
510
|
-
}
|
511
|
-
return value instanceof Date === true && value.toString() !== 'Invalid Date';
|
512
|
-
}
|
513
|
-
},
|
514
|
-
day: {
|
515
|
-
hasLabel: true,
|
516
|
-
message(component) {
|
517
|
-
return component.t(component.errorMessage('invalid_day'), {
|
518
|
-
field: component.errorLabel,
|
519
|
-
data: component.data
|
520
|
-
});
|
521
|
-
},
|
522
|
-
check(component, setting, value) {
|
523
|
-
if (!value) {
|
524
|
-
return true;
|
525
|
-
}
|
526
|
-
const [DAY, MONTH, YEAR] = component.dayFirst ? [0, 1, 2] : [1, 0, 2];
|
527
|
-
const values = value.split('/').map(x => parseInt(x, 10)), day = values[DAY], month = values[MONTH], year = values[YEAR], maxDay = getDaysInMonthCount(month, year);
|
528
|
-
if (day < 0 || day > maxDay) {
|
529
|
-
return false;
|
530
|
-
}
|
531
|
-
if (month < 0 || month > 12) {
|
532
|
-
return false;
|
533
|
-
}
|
534
|
-
if (year < 0 || year > 9999) {
|
535
|
-
return false;
|
536
|
-
}
|
537
|
-
return true;
|
538
|
-
function isLeapYear(year) {
|
539
|
-
// Year is leap if it is evenly divisible by 400 or evenly divisible by 4 and not evenly divisible by 100.
|
540
|
-
return !(year % 400) || (!!(year % 100) && !(year % 4));
|
541
|
-
}
|
542
|
-
function getDaysInMonthCount(month, year) {
|
543
|
-
switch (month) {
|
544
|
-
case 1: // January
|
545
|
-
case 3: // March
|
546
|
-
case 5: // May
|
547
|
-
case 7: // July
|
548
|
-
case 8: // August
|
549
|
-
case 10: // October
|
550
|
-
case 12: // December
|
551
|
-
return 31;
|
552
|
-
case 4: // April
|
553
|
-
case 6: // June
|
554
|
-
case 9: // September
|
555
|
-
case 11: // November
|
556
|
-
return 30;
|
557
|
-
case 2: // February
|
558
|
-
return isLeapYear(year) ? 29 : 28;
|
559
|
-
default:
|
560
|
-
return 31;
|
561
|
-
}
|
562
|
-
}
|
563
|
-
}
|
564
|
-
},
|
565
|
-
pattern: {
|
566
|
-
key: 'validate.pattern',
|
567
|
-
hasLabel: true,
|
568
|
-
message(component, setting) {
|
569
|
-
return component.t(_.get(component, 'component.validate.patternMessage', component.errorMessage('pattern')), {
|
570
|
-
field: component.errorLabel,
|
571
|
-
pattern: setting,
|
572
|
-
data: component.data
|
573
|
-
});
|
574
|
-
},
|
575
|
-
check(component, setting, value) {
|
576
|
-
if (component.isEmpty(value))
|
577
|
-
return true;
|
578
|
-
const pattern = setting;
|
579
|
-
if (!pattern) {
|
580
|
-
return true;
|
581
|
-
}
|
582
|
-
const regex = new RegExp(`^${pattern}$`);
|
583
|
-
return regex.test(value);
|
584
|
-
}
|
585
|
-
},
|
586
|
-
json: {
|
587
|
-
key: 'validate.json',
|
588
|
-
check(component, setting, value, data, index, row) {
|
589
|
-
if (!setting) {
|
590
|
-
return true;
|
591
|
-
}
|
592
|
-
const valid = component.evaluate(setting, {
|
593
|
-
data,
|
594
|
-
row,
|
595
|
-
rowIndex: index,
|
596
|
-
input: value
|
597
|
-
});
|
598
|
-
if (valid === null) {
|
599
|
-
return true;
|
600
|
-
}
|
601
|
-
return valid;
|
602
|
-
}
|
603
|
-
},
|
604
|
-
mask: {
|
605
|
-
key: 'inputMask',
|
606
|
-
hasLabel: true,
|
607
|
-
message(component) {
|
608
|
-
return component.t(component.errorMessage('mask'), {
|
609
|
-
field: component.errorLabel,
|
610
|
-
data: component.data
|
611
|
-
});
|
612
|
-
},
|
613
|
-
check(component, setting, value) {
|
614
|
-
let inputMask;
|
615
|
-
if (component.isMultipleMasksField) {
|
616
|
-
const maskName = value ? value.maskName : undefined;
|
617
|
-
const formioInputMask = component.getMaskByName(maskName);
|
618
|
-
if (formioInputMask) {
|
619
|
-
inputMask = formioInputMask;
|
620
|
-
}
|
621
|
-
value = value ? value.value : value;
|
622
|
-
}
|
623
|
-
else {
|
624
|
-
inputMask = setting;
|
625
|
-
}
|
626
|
-
inputMask = inputMask ? getInputMask(inputMask) : null;
|
627
|
-
if (value && inputMask && !component.skipMaskValidation) {
|
628
|
-
// If char which is used inside mask placeholder was used in the mask, replace it with space to prevent errors
|
629
|
-
inputMask = inputMask.map((char) => char === component.placeholderChar ? ' ' : char);
|
630
|
-
return matchInputMask(value, inputMask);
|
631
|
-
}
|
632
|
-
return true;
|
633
|
-
}
|
634
|
-
},
|
635
|
-
custom: {
|
636
|
-
key: 'validate.custom',
|
637
|
-
message(component) {
|
638
|
-
return component.t(component.errorMessage('custom'), {
|
639
|
-
field: component.errorLabel,
|
640
|
-
data: component.data
|
641
|
-
});
|
642
|
-
},
|
643
|
-
check(component, setting, value, data, index, row) {
|
644
|
-
if (!setting) {
|
645
|
-
return true;
|
646
|
-
}
|
647
|
-
const valid = component.evaluate(setting, {
|
648
|
-
valid: true,
|
649
|
-
data,
|
650
|
-
rowIndex: index,
|
651
|
-
row,
|
652
|
-
input: value
|
653
|
-
}, 'valid', true);
|
654
|
-
if (valid === null) {
|
655
|
-
return true;
|
656
|
-
}
|
657
|
-
return valid;
|
658
|
-
}
|
659
|
-
},
|
660
|
-
maxDate: {
|
661
|
-
key: 'maxDate',
|
662
|
-
hasLabel: true,
|
663
|
-
message(component, setting) {
|
664
|
-
const date = getDateSetting(setting);
|
665
|
-
return component.t(component.errorMessage('maxDate'), {
|
666
|
-
field: component.errorLabel,
|
667
|
-
maxDate: moment(date).format(component.format),
|
668
|
-
});
|
669
|
-
},
|
670
|
-
check(component, setting, value) {
|
671
|
-
//if any parts of day are missing, skip maxDate validation
|
672
|
-
if (component.isPartialDay && component.isPartialDay(value)) {
|
673
|
-
return true;
|
674
|
-
}
|
675
|
-
const date = component.getValidationFormat ? moment(value, component.getValidationFormat()) : moment(value);
|
676
|
-
const maxDate = getDateSetting(setting);
|
677
|
-
if (_.isNull(maxDate)) {
|
678
|
-
return true;
|
679
|
-
}
|
680
|
-
else {
|
681
|
-
maxDate.setHours(0, 0, 0, 0);
|
682
|
-
}
|
683
|
-
return date.isBefore(maxDate) || date.isSame(maxDate);
|
684
|
-
}
|
685
|
-
},
|
686
|
-
minDate: {
|
687
|
-
key: 'minDate',
|
688
|
-
hasLabel: true,
|
689
|
-
message(component, setting) {
|
690
|
-
const date = getDateSetting(setting);
|
691
|
-
return component.t(component.errorMessage('minDate'), {
|
692
|
-
field: component.errorLabel,
|
693
|
-
minDate: moment(date).format(component.format),
|
694
|
-
});
|
695
|
-
},
|
696
|
-
check(component, setting, value) {
|
697
|
-
//if any parts of day are missing, skip minDate validation
|
698
|
-
if (component.isPartialDay && component.isPartialDay(value)) {
|
699
|
-
return true;
|
700
|
-
}
|
701
|
-
const date = component.getValidationFormat ? moment(value, component.getValidationFormat()) : moment(value);
|
702
|
-
const minDate = getDateSetting(setting);
|
703
|
-
if (_.isNull(minDate)) {
|
704
|
-
return true;
|
705
|
-
}
|
706
|
-
else {
|
707
|
-
minDate.setHours(0, 0, 0, 0);
|
708
|
-
}
|
709
|
-
return date.isAfter(minDate) || date.isSame(minDate);
|
710
|
-
}
|
711
|
-
},
|
712
|
-
minYear: {
|
713
|
-
key: 'minYear',
|
714
|
-
hasLabel: true,
|
715
|
-
message(component, setting) {
|
716
|
-
return component.t(component.errorMessage('minYear'), {
|
717
|
-
field: component.errorLabel,
|
718
|
-
minYear: setting,
|
719
|
-
});
|
720
|
-
},
|
721
|
-
check(component, setting, value) {
|
722
|
-
const minYear = setting;
|
723
|
-
let year = /\d{4}$/.exec(value);
|
724
|
-
year = year ? year[0] : null;
|
725
|
-
if (!(+minYear) || !(+year)) {
|
726
|
-
return true;
|
727
|
-
}
|
728
|
-
return +year >= +minYear;
|
729
|
-
}
|
730
|
-
},
|
731
|
-
maxYear: {
|
732
|
-
key: 'maxYear',
|
733
|
-
hasLabel: true,
|
734
|
-
message(component, setting) {
|
735
|
-
return component.t(component.errorMessage('maxYear'), {
|
736
|
-
field: component.errorLabel,
|
737
|
-
maxYear: setting,
|
738
|
-
});
|
739
|
-
},
|
740
|
-
check(component, setting, value) {
|
741
|
-
const maxYear = setting;
|
742
|
-
let year = /\d{4}$/.exec(value);
|
743
|
-
year = year ? year[0] : null;
|
744
|
-
if (!(+maxYear) || !(+year)) {
|
745
|
-
return true;
|
746
|
-
}
|
747
|
-
return +year <= +maxYear;
|
748
|
-
}
|
749
|
-
},
|
750
|
-
calendar: {
|
751
|
-
key: 'validate.calendar',
|
752
|
-
messageText: '',
|
753
|
-
hasLabel: true,
|
754
|
-
message(component) {
|
755
|
-
return component.t(component.errorMessage(this.validators.calendar.messageText), {
|
756
|
-
field: component.errorLabel,
|
757
|
-
maxDate: moment(component.dataValue).format(component.format),
|
758
|
-
});
|
759
|
-
},
|
760
|
-
check(component, setting, value, data, index) {
|
761
|
-
this.validators.calendar.messageText = '';
|
762
|
-
const widget = component.getWidget(index);
|
763
|
-
if (!widget) {
|
764
|
-
return true;
|
765
|
-
}
|
766
|
-
const { settings, enteredDate } = widget;
|
767
|
-
const { minDate, maxDate, format } = settings;
|
768
|
-
const momentFormat = [convertFormatToMoment(format)];
|
769
|
-
if (momentFormat[0].match(/M{3,}/g)) {
|
770
|
-
momentFormat.push(momentFormat[0].replace(/M{3,}/g, 'MM'));
|
771
|
-
}
|
772
|
-
if (!value && enteredDate) {
|
773
|
-
const { message, result } = checkInvalidDate(enteredDate, momentFormat, minDate, maxDate);
|
774
|
-
if (!result) {
|
775
|
-
this.validators.calendar.messageText = message;
|
776
|
-
return result;
|
777
|
-
}
|
778
|
-
}
|
779
|
-
if (value && enteredDate) {
|
780
|
-
if (moment(value).format() !== moment(enteredDate, momentFormat, true).format() && enteredDate.match(/_/gi)) {
|
781
|
-
this.validators.calendar.messageText = CALENDAR_ERROR_MESSAGES.INCOMPLETE;
|
782
|
-
return false;
|
783
|
-
}
|
784
|
-
else {
|
785
|
-
widget.enteredDate = '';
|
786
|
-
return true;
|
787
|
-
}
|
788
|
-
}
|
789
|
-
}
|
790
|
-
},
|
791
|
-
time: {
|
792
|
-
key: 'validate.time',
|
793
|
-
messageText: 'Invalid time',
|
794
|
-
hasLabel: true,
|
795
|
-
message(component) {
|
796
|
-
return component.t(component.errorMessage(this.validators.time.messageText), {
|
797
|
-
field: component.errorLabel
|
798
|
-
});
|
799
|
-
},
|
800
|
-
check(component, setting, value) {
|
801
|
-
if (component.isEmpty(value))
|
802
|
-
return true;
|
803
|
-
return moment(value, component.component.format).isValid();
|
804
|
-
}
|
805
|
-
},
|
806
|
-
availableValueProperty: {
|
807
|
-
key: 'validate.availableValueProperty',
|
808
|
-
method: 'validateValueProperty',
|
809
|
-
messageText: 'Invalid Value Property',
|
810
|
-
hasLabel: true,
|
811
|
-
message(component) {
|
812
|
-
return component.t(component.errorMessage(this.validators.availableValueProperty.messageText), {
|
813
|
-
field: component.errorLabel,
|
814
|
-
});
|
815
|
-
},
|
816
|
-
check(component, setting, value) {
|
817
|
-
if (component.component.dataSrc === 'url' && (_.isUndefined(value) || _.isObject(value))) {
|
818
|
-
return false;
|
819
|
-
}
|
820
|
-
return true;
|
821
|
-
}
|
822
|
-
}
|
823
|
-
};
|
824
|
-
}
|
825
|
-
checkValidator(component, validator, setting, value, data, index, row, async) {
|
826
|
-
let resultOrPromise = null;
|
827
|
-
// Allow each component to override their own validators by implementing the validator.method
|
828
|
-
if (validator.method && (typeof component[validator.method] === 'function')) {
|
829
|
-
resultOrPromise = component[validator.method](setting, value, data, index, row, async);
|
830
|
-
}
|
831
|
-
else {
|
832
|
-
resultOrPromise = validator.check.call(this, component, setting, value, data, index, row, async);
|
833
|
-
}
|
834
|
-
const processResult = result => {
|
835
|
-
if (typeof result === 'string') {
|
836
|
-
return result;
|
837
|
-
}
|
838
|
-
if (!result && validator.message) {
|
839
|
-
return validator.message.call(this, component, setting, index, row);
|
840
|
-
}
|
841
|
-
return '';
|
842
|
-
};
|
843
|
-
if (async) {
|
844
|
-
return Promise.resolve(resultOrPromise).then(processResult);
|
845
|
-
}
|
846
|
-
else {
|
847
|
-
return processResult(resultOrPromise);
|
848
|
-
}
|
849
|
-
}
|
850
|
-
validate(component, validatorName, value, data, index, row, async, conditionallyVisible, validationObj) {
|
851
|
-
// Skip validation for conditionally hidden components
|
852
|
-
if (!conditionallyVisible) {
|
853
|
-
return false;
|
854
|
-
}
|
855
|
-
const validator = this.validators[validatorName];
|
856
|
-
const setting = _.get(validationObj || component.component, validator.key, null);
|
857
|
-
const resultOrPromise = this.checkValidator(component, validator, setting, value, data, index, row, async);
|
858
|
-
const processResult = result => {
|
859
|
-
if (result) {
|
860
|
-
const resultData = {
|
861
|
-
message: unescapeHTML(_.get(result, 'message', result)),
|
862
|
-
level: _.get(result, 'level') === 'warning' ? 'warning' : 'error',
|
863
|
-
path: getArrayFromComponentPath(component.path || ''),
|
864
|
-
context: {
|
865
|
-
validator: validatorName,
|
866
|
-
hasLabel: validator.hasLabel,
|
867
|
-
setting,
|
868
|
-
key: component.key,
|
869
|
-
label: component.label,
|
870
|
-
value,
|
871
|
-
index,
|
872
|
-
input: component.refs.input?.[index]
|
873
|
-
}
|
874
|
-
};
|
875
|
-
if (validatorName === 'unique' && component.conflictId) {
|
876
|
-
resultData.conflictId = component.conflictId;
|
877
|
-
}
|
878
|
-
return resultData;
|
879
|
-
}
|
880
|
-
else {
|
881
|
-
return false;
|
882
|
-
}
|
883
|
-
};
|
884
|
-
if (async) {
|
885
|
-
return Promise.resolve(resultOrPromise).then(processResult);
|
886
|
-
}
|
887
|
-
else {
|
888
|
-
return processResult(resultOrPromise);
|
889
|
-
}
|
890
|
-
}
|
891
|
-
checkComponent(component, data, row, includeWarnings = false, async = false) {
|
892
|
-
const isServerSidePersistent = typeof process !== 'undefined'
|
893
|
-
&& _.get(process, 'release.name') === 'node'
|
894
|
-
&& !_.defaultTo(component.component.persistent, true);
|
895
|
-
// If we're server-side and it's not a persistent component, don't run validation at all
|
896
|
-
if (isServerSidePersistent || component.component.validate === false) {
|
897
|
-
return async ? Promise.resolve([]) : [];
|
898
|
-
}
|
899
|
-
data = data || component.rootValue;
|
900
|
-
row = row || component.data;
|
901
|
-
const values = (component.component.multiple && Array.isArray(component.validationValue))
|
902
|
-
? component.validationValue
|
903
|
-
: [component.validationValue];
|
904
|
-
const conditionallyVisible = component.conditionallyVisible();
|
905
|
-
const addonsValidations = [];
|
906
|
-
if (component?.addons?.length) {
|
907
|
-
values.forEach((value) => {
|
908
|
-
component.addons.forEach((addon) => {
|
909
|
-
if (!addon.checkValidity(value)) {
|
910
|
-
addonsValidations.push(...(addon.errors || []));
|
911
|
-
}
|
912
|
-
});
|
913
|
-
});
|
914
|
-
}
|
915
|
-
// If this component has the new validation system enabled, use it instead.
|
916
|
-
const validations = _.get(component, 'component.validations');
|
917
|
-
let nextGenResultsOrPromises = [];
|
918
|
-
if (validations && Array.isArray(validations) && validations.length) {
|
919
|
-
const validationsGroupedByMode = _.chain(validations)
|
920
|
-
.groupBy((validation) => validation.mode)
|
921
|
-
.value();
|
922
|
-
if (component.calculateCondition) {
|
923
|
-
includeWarnings = true;
|
924
|
-
const uiGroupedValidation = _.chain(validationsGroupedByMode.ui)
|
925
|
-
.filter('active')
|
926
|
-
.groupBy((validation) => validation.group || null)
|
927
|
-
.value();
|
928
|
-
const commonValidations = uiGroupedValidation.null || [];
|
929
|
-
delete uiGroupedValidation.null;
|
930
|
-
commonValidations.forEach(({ condition, message, severity }) => {
|
931
|
-
if (!component.calculateCondition(condition)) {
|
932
|
-
nextGenResultsOrPromises.push({
|
933
|
-
level: severity || 'error',
|
934
|
-
message: component.t(message),
|
935
|
-
componentInstance: component,
|
936
|
-
});
|
937
|
-
}
|
938
|
-
});
|
939
|
-
_.forEach(uiGroupedValidation, (validationGroup) => {
|
940
|
-
_.forEach(validationGroup, ({ condition, message, severity }) => {
|
941
|
-
if (!component.calculateCondition(condition)) {
|
942
|
-
nextGenResultsOrPromises.push({
|
943
|
-
level: severity || 'error',
|
944
|
-
message: component.t(message),
|
945
|
-
componentInstance: component,
|
946
|
-
});
|
947
|
-
return false;
|
948
|
-
}
|
949
|
-
});
|
950
|
-
});
|
951
|
-
}
|
952
|
-
else {
|
953
|
-
nextGenResultsOrPromises = this.checkValidations(component, validations, data, row, values, async);
|
954
|
-
}
|
955
|
-
if (component.validators.includes('custom') && validationsGroupedByMode.js) {
|
956
|
-
_.each(validationsGroupedByMode.js, (validation) => {
|
957
|
-
nextGenResultsOrPromises.push(_.map(values, (value, index) => this.validate(component, 'custom', value, data, index, row, async, conditionallyVisible, validation)));
|
958
|
-
});
|
959
|
-
}
|
960
|
-
if (component.validators.includes('json') && validationsGroupedByMode.json) {
|
961
|
-
_.each(validationsGroupedByMode.json, (validation) => {
|
962
|
-
nextGenResultsOrPromises.push(_.map(values, (value, index) => this.validate(component, 'json', value, data, index, row, async, conditionallyVisible, validation)));
|
963
|
-
});
|
964
|
-
}
|
965
|
-
}
|
966
|
-
const validateCustom = _.get(component, 'component.validate.custom');
|
967
|
-
const customErrorMessage = _.get(component, 'component.validate.customMessage');
|
968
|
-
// Run primary validators
|
969
|
-
const resultsOrPromises = _(component.validators).chain()
|
970
|
-
.map(validatorName => {
|
971
|
-
if (!this.validators.hasOwnProperty(validatorName)) {
|
972
|
-
return {
|
973
|
-
message: `Validator for "${validatorName}" is not defined`,
|
974
|
-
level: 'warning',
|
975
|
-
context: {
|
976
|
-
validator: validatorName,
|
977
|
-
key: component.key,
|
978
|
-
label: component.label
|
979
|
-
}
|
980
|
-
};
|
981
|
-
}
|
982
|
-
// Handle the case when there is no values defined and it is required.
|
983
|
-
if (validatorName === 'required' && !values.length) {
|
984
|
-
return [this.validate(component, validatorName, null, data, 0, row, async, conditionallyVisible)];
|
985
|
-
}
|
986
|
-
return _.map(values, (value, index) => this.validate(component, validatorName, value, data, index, row, async, conditionallyVisible));
|
987
|
-
})
|
988
|
-
.flatten()
|
989
|
-
.value();
|
990
|
-
// Run the "unique" pseudo-validator
|
991
|
-
component.component.validate = component.component.validate || {};
|
992
|
-
component.component.validate.unique = component.component.unique;
|
993
|
-
resultsOrPromises.push(this.validate(component, 'unique', component.validationValue, data, 0, data, async, conditionallyVisible));
|
994
|
-
// Run the "multiple" pseudo-validator
|
995
|
-
component.component.validate.multiple = component.component.multiple;
|
996
|
-
resultsOrPromises.push(this.validate(component, 'multiple', component.validationValue, data, 0, data, async, conditionallyVisible));
|
997
|
-
resultsOrPromises.push(...addonsValidations);
|
998
|
-
resultsOrPromises.push(...nextGenResultsOrPromises);
|
999
|
-
// Define how results should be formatted
|
1000
|
-
const formatResults = results => {
|
1001
|
-
// Condense to a single flat array
|
1002
|
-
results = _(results).chain().flatten().compact().value();
|
1003
|
-
if (customErrorMessage || validateCustom) {
|
1004
|
-
_.each(results, result => {
|
1005
|
-
result.message = component.t(customErrorMessage || result.message, {
|
1006
|
-
field: component.errorLabel,
|
1007
|
-
data,
|
1008
|
-
row,
|
1009
|
-
error: result
|
1010
|
-
});
|
1011
|
-
result.context.hasLabel = false;
|
1012
|
-
});
|
1013
|
-
}
|
1014
|
-
return includeWarnings ? results : _.reject(results, result => result.level === 'warning');
|
1015
|
-
};
|
1016
|
-
// Wait for results if using async mode, otherwise process and return immediately
|
1017
|
-
if (async) {
|
1018
|
-
return Promise.all(resultsOrPromises).then(formatResults);
|
1019
|
-
}
|
1020
|
-
else {
|
1021
|
-
return formatResults(resultsOrPromises);
|
1022
|
-
}
|
1023
|
-
}
|
1024
|
-
/**
|
1025
|
-
* Use the new validations engine to evaluate any errors.
|
1026
|
-
*
|
1027
|
-
* @param component
|
1028
|
-
* @param validations
|
1029
|
-
* @param data
|
1030
|
-
* @param row
|
1031
|
-
* @param values
|
1032
|
-
* @returns {any[]}
|
1033
|
-
*/
|
1034
|
-
checkValidations(component, validations, data, row, values, async) {
|
1035
|
-
// Get results.
|
1036
|
-
const results = validations.map((validation) => {
|
1037
|
-
return this.checkRule(component, validation, data, row, values, async);
|
1038
|
-
});
|
1039
|
-
// Flatten array and filter out empty results.
|
1040
|
-
const messages = results.reduce((prev, result) => {
|
1041
|
-
if (result) {
|
1042
|
-
return [...prev, ...result];
|
1043
|
-
}
|
1044
|
-
return prev;
|
1045
|
-
}, []).filter((result) => result);
|
1046
|
-
// Keep only the last error for each rule.
|
1047
|
-
const rules = messages.reduce((prev, message) => {
|
1048
|
-
prev[message.context.validator] = message;
|
1049
|
-
return prev;
|
1050
|
-
}, {});
|
1051
|
-
return Object.values(rules);
|
1052
|
-
}
|
1053
|
-
checkRule(component, validation, data, row, values, async) {
|
1054
|
-
const Rule = Rules.getRule(validation.rule);
|
1055
|
-
const results = [];
|
1056
|
-
if (Rule) {
|
1057
|
-
const rule = new Rule(component, validation.settings, this.config);
|
1058
|
-
values.map((value, index) => {
|
1059
|
-
const result = rule.check(value, data, row, async);
|
1060
|
-
if (result !== true) {
|
1061
|
-
results.push({
|
1062
|
-
level: validation.level || 'error',
|
1063
|
-
message: component.t(validation.message || rule.defaultMessage, {
|
1064
|
-
settings: validation.settings,
|
1065
|
-
field: component.errorLabel,
|
1066
|
-
data,
|
1067
|
-
row,
|
1068
|
-
error: result,
|
1069
|
-
}),
|
1070
|
-
context: {
|
1071
|
-
key: component.key,
|
1072
|
-
index,
|
1073
|
-
label: component.label,
|
1074
|
-
validator: validation.rule,
|
1075
|
-
},
|
1076
|
-
});
|
1077
|
-
}
|
1078
|
-
});
|
1079
|
-
}
|
1080
|
-
// If there are no results, return false so it is removed by filter.
|
1081
|
-
return results.length === 0 ? false : results;
|
1082
|
-
}
|
1083
|
-
get check() {
|
1084
|
-
return this.checkComponent;
|
1085
|
-
}
|
1086
|
-
get() {
|
1087
|
-
_.get.call(this, arguments);
|
1088
|
-
}
|
1089
|
-
each() {
|
1090
|
-
_.each.call(this, arguments);
|
1091
|
-
}
|
1092
|
-
has() {
|
1093
|
-
_.has.call(this, arguments);
|
1094
|
-
}
|
1095
|
-
}
|
1096
|
-
ValidationChecker.config = {
|
1097
|
-
db: null,
|
1098
|
-
token: null,
|
1099
|
-
form: null,
|
1100
|
-
submission: null
|
1101
|
-
};
|
1102
|
-
const instance = new ValidationChecker();
|
1103
|
-
export { instance as default, ValidationChecker };
|