@cnamts/synapse 1.0.23 → 1.0.24
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/dist/AutocompleteFilter-BWLR3U7W.js +114 -0
- package/dist/AutocompleteFilter-D9jzRzAL.cjs +1 -0
- package/dist/{DateFilter-Dc-gSGwk.js → DateFilter-BpwFexzi.js} +1 -1
- package/dist/DateFilter-DTUl8hb1.cjs +1 -0
- package/dist/{NumberFilter-vP38Wp6j.js → NumberFilter-Bz_NTdX9.js} +3 -3
- package/dist/NumberFilter-MAEojdk0.cjs +1 -0
- package/dist/PeriodFilter-CC4WgIhl.cjs +1 -0
- package/dist/{PeriodFilter-Ba1uYUnT.js → PeriodFilter-DX_wy9g-.js} +1 -1
- package/dist/SelectFilter-BR3fvl-a.cjs +1 -0
- package/dist/SelectFilter-xqiPtPgX.js +135 -0
- package/dist/{TextFilter-B84dpnoq.js → TextFilter-BBl3JFqK.js} +7 -7
- package/dist/TextFilter-CCfYFl5F.cjs +1 -0
- package/dist/apLightTheme-CFSRrjv2.cjs +1 -0
- package/dist/apLightTheme-D1P4jcD0.js +1231 -0
- package/dist/components/Amelipro/AmeliproAutoCompleteField/AmeliproAutoCompleteField.d.ts +7022 -9616
- package/dist/components/Amelipro/AmeliproCarousel/AmeliproCarousel.d.ts +2 -2
- package/dist/components/Amelipro/AmeliproIconBtn/AmeliproIconBtn.d.ts +2 -2
- package/dist/components/Amelipro/AmeliproPostalAddressField/AmeliproPostalAddressCityRow/AmeliproPostalAddressCityRow.d.ts +40 -40
- package/dist/components/Amelipro/AmeliproPostalAddressField/AmeliproPostalAddressField.d.ts +60 -60
- package/dist/components/Amelipro/AmeliproSelect/AmeliproSelect.d.ts +7168 -9762
- package/dist/components/Amelipro/AmeliproStepper/AmeliproStepper.d.ts +2 -2
- package/dist/components/Amelipro/AmeliproTabs/AmeliproTabs.d.ts +7501 -10095
- package/dist/components/Amelipro/AmeliproTextArea/AmeliproTextArea.d.ts +21 -21
- package/dist/components/Amelipro/AmeliproTextField/AmeliproTextField.d.ts +41 -41
- package/dist/components/Amelipro/StructureMenu/StructureTabs/StructureTabs.d.ts +2 -2
- package/dist/components/CookiesSelection/CookiesInformation/CookiesInformation.d.ts +20 -498
- package/dist/components/Customs/Selects/SyAutocomplete/SyAutocomplete.d.ts +108 -146
- package/dist/components/Customs/Selects/SyInputSelect/SyInputSelect.d.ts +5 -5
- package/dist/components/Customs/Selects/SySelect/SySelect.d.ts +12 -16
- package/dist/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.d.ts +8 -8
- package/dist/components/Customs/SyCheckbox/SyCheckbox.d.ts +28 -506
- package/dist/components/Customs/SyRadioGroup/SyRadioGroup.d.ts +28 -506
- package/dist/components/Customs/SyTextField/SyTextField.d.ts +65 -85
- package/dist/components/DatePicker/CalendarMode/DatePicker.d.ts +627 -771
- package/dist/components/DatePicker/ComplexDatePicker/ComplexDatePicker.d.ts +315 -402
- package/dist/components/DatePicker/DateTextInput/DateTextInput.d.ts +112 -155
- package/dist/components/DatePicker/composables/index.d.ts +1 -0
- package/dist/components/DatePicker/composables/useDatePickerFocusTrap.d.ts +11 -0
- package/dist/components/DatePicker/composables/useDateTextField.d.ts +4 -4
- package/dist/components/DatePicker/composables/useDateValidation.d.ts +3 -3
- package/dist/components/DatePicker/composables/useInputBlurHandler.d.ts +2 -2
- package/dist/components/DatePicker/composables/useManualDateValidation.d.ts +2 -2
- package/dist/components/HeaderNavigationBar/HeaderNavigationBar.d.ts +4 -4
- package/dist/components/HeaderToolbar/HeaderToolbar.d.ts +20 -28
- package/dist/components/LunarCalendar/useLunarCalendarValidation.d.ts +3 -3
- package/dist/components/MonthPicker/MonthPicker.d.ts +86 -122
- package/dist/components/MonthPicker/MonthPickerText/MonthPickerInput.d.ts +85 -121
- package/dist/components/NirField/NirField.d.ts +206 -270
- package/dist/components/NirField/locales.d.ts +10 -10
- package/dist/components/NirField/useNirValidation.d.ts +64 -0
- package/dist/components/PasswordField/PasswordField.d.ts +8 -9
- package/dist/components/PeriodField/PeriodField.d.ts +1352 -1640
- package/dist/components/PhoneField/PhoneField.d.ts +88 -124
- package/dist/components/RangeField/RangeSlider/RangeSlider.d.ts +12 -12
- package/dist/components/SyTextArea/SyTextArea.d.ts +34 -14
- package/dist/components/SyTextArea/useDefaultValidationRules.d.ts +11 -0
- package/dist/components/Tables/SyServerTable/SyServerTable.d.ts +9 -6
- package/dist/components/Tables/SyTable/SyTable.d.ts +9 -6
- package/dist/components/Tables/common/SyTableFilter.d.ts +2 -3
- package/dist/components/Tables/common/SyTablePagination.d.ts +17 -19
- package/dist/components/Tables/common/filters/AutocompleteFilter.d.ts +120 -0
- package/dist/components/Tables/common/filters/locales.d.ts +0 -1
- package/dist/components/Tables/common/types.d.ts +19 -3
- package/dist/components/Tables/common/useClickableTableRow.d.ts +17 -0
- package/dist/components/Tables/common/usePagination.d.ts +3 -1
- package/dist/components/Tables/common/usePinnedColumns.d.ts +31 -0
- package/dist/components/Tables/common/useTableHeaders.d.ts +2 -0
- package/dist/components/Tables/common/useTableRowCheckboxAccessibility.d.ts +5 -0
- package/dist/components/UploadWorkflow/UploadWorkflow.d.ts +6 -6
- package/dist/composables/date/useDatePickerAccessibility.d.ts +1 -1
- package/dist/composables/rules/useFieldValidation.d.ts +4 -4
- package/dist/composables/unifyValidation/useCustomValidation.d.ts +8 -0
- package/dist/composables/unifyValidation/useValidation.d.ts +102 -0
- package/dist/composables/unifyValidation/useVuetifyValidation.d.ts +18 -0
- package/dist/composables/useFormFieldErrorHandling.d.ts +2 -2
- package/dist/composables/validation/useFormValidation.d.ts +11 -2
- package/dist/composables/validation/useValidation.d.ts +15 -9
- package/dist/design-system-v3.d.ts +2 -0
- package/dist/design-system-v3.js +186 -187
- package/dist/design-system-v3.umd.cjs +1 -1066
- package/dist/{main-aLKwdMi1.js → main-BtTqyn4z.js} +16434 -15672
- package/dist/main-C1e3eoxd.cjs +1067 -0
- package/dist/main.d.ts +0 -1
- package/dist/synapse.css +1 -0
- package/dist/tooth-11-D3sLWv2n.cjs +1 -0
- package/dist/tooth-12-CXrLuH03.cjs +1 -0
- package/dist/tooth-13-BSfo5fpT.cjs +1 -0
- package/dist/tooth-14-DMzulx0h.cjs +1 -0
- package/dist/tooth-15-BKRFVi-9.cjs +1 -0
- package/dist/tooth-16-CpuxAbuM.cjs +1 -0
- package/dist/tooth-17-BPoahUdg.cjs +1 -0
- package/dist/tooth-18-DhHJz8sy.cjs +1 -0
- package/dist/tooth-21-Dgd5hn_X.cjs +1 -0
- package/dist/tooth-22-C2Tn19sB.cjs +1 -0
- package/dist/tooth-23-C9uaaSGb.cjs +1 -0
- package/dist/tooth-24-BrK9UGpf.cjs +1 -0
- package/dist/tooth-25-CE_EfGNp.cjs +1 -0
- package/dist/tooth-26-Ctv4i9Fy.cjs +1 -0
- package/dist/tooth-27-C5J7JkWM.cjs +1 -0
- package/dist/tooth-28-Z9oWqjo0.cjs +1 -0
- package/dist/tooth-31-BrYqmkTi.cjs +1 -0
- package/dist/tooth-32-BNNR0oCZ.cjs +1 -0
- package/dist/tooth-33-DuxvqO2J.cjs +1 -0
- package/dist/tooth-34-BCSCXMB6.cjs +1 -0
- package/dist/tooth-35-BLUXkX88.cjs +1 -0
- package/dist/tooth-36-IrKHYqlA.cjs +1 -0
- package/dist/tooth-37-BYqpdMwo.cjs +1 -0
- package/dist/tooth-38-B_eNXXdu.cjs +1 -0
- package/dist/tooth-41-Ddva4Ot8.cjs +1 -0
- package/dist/tooth-42-szcDqlM0.cjs +1 -0
- package/dist/tooth-43-B3ka6rQm.cjs +1 -0
- package/dist/tooth-44-CazyQucj.cjs +1 -0
- package/dist/tooth-45-B4HQtc8n.cjs +1 -0
- package/dist/tooth-46-BPM40gbG.cjs +1 -0
- package/dist/tooth-47-Dvr20dlh.cjs +1 -0
- package/dist/tooth-48-Bd8ljGsF.cjs +1 -0
- package/dist/tooth-51-OBpwCOF3.cjs +1 -0
- package/dist/tooth-52-aKxyHcmq.cjs +1 -0
- package/dist/tooth-53-vCwJjTOc.cjs +1 -0
- package/dist/tooth-54-DsWu2iFy.cjs +1 -0
- package/dist/tooth-55-BxC1X2Dn.cjs +1 -0
- package/dist/tooth-61-BbLvxMQi.cjs +1 -0
- package/dist/tooth-62-CmTkWczP.cjs +1 -0
- package/dist/tooth-63-DI7l_2qI.cjs +1 -0
- package/dist/tooth-64-B21sOsJh.cjs +1 -0
- package/dist/tooth-65-D2ZC2VEr.cjs +1 -0
- package/dist/tooth-71-D473PPO5.cjs +1 -0
- package/dist/tooth-72-Drh1wnNu.cjs +1 -0
- package/dist/tooth-73-DzlwYI23.cjs +1 -0
- package/dist/tooth-74-8aGvcZPg.cjs +1 -0
- package/dist/tooth-75-BFK7At_r.cjs +1 -0
- package/dist/tooth-81-BZmR-I0M.cjs +1 -0
- package/dist/tooth-82-euVfUUZV.cjs +1 -0
- package/dist/tooth-83-KV010j64.cjs +1 -0
- package/dist/tooth-84-BBg1RjhZ.cjs +1 -0
- package/dist/tooth-85-Cr-kc1wM.cjs +1 -0
- package/dist/vuetifyConfig.js +561 -0
- package/dist/vuetifyConfig.umd.cjs +1 -0
- package/package.json +10 -4
- package/src/assets/overrides/_btns.scss +0 -6
- package/src/assets/overrides/_icons.scss +9 -1
- package/src/assets/overrides/_typography.scss +0 -10
- package/src/components/Amelipro/AmeliproAutoCompleteField/__tests__/__snapshots__/AmeliproAutoCompleteField.spec.ts.snap +2 -2
- package/src/components/Amelipro/AmeliproHeader/AmeliproHeaderBar/AmeliproHeaderBrandSection/__tests__/__snapshots__/AmeliproHeaderBrandSection.spec.ts.snap +1 -1
- package/src/components/Amelipro/AmeliproTextArea/__tests__/__snapshots__/AmeliproTextArea.spec.ts.snap +2 -2
- package/src/components/Captcha/accessibilite/Accessibility.mdx +86 -8
- package/src/components/Captcha/tests/__snapshots__/Captcha.spec.ts.snap +12 -12
- package/src/components/ChipList/ChipList.stories.ts +0 -15
- package/src/components/ChipList/ChipList.vue +5 -1
- package/src/components/ChipList/accessibilite/Accessibility.mdx +83 -10
- package/src/components/ChipList/tests/ChipList.a11y.spec.ts +41 -0
- package/src/components/Customs/Selects/SelectBtnField/accessibilite/Accessibility.mdx +0 -9
- package/src/components/Customs/Selects/SyAutocomplete/SyAutocomplete.vue +22 -5
- package/src/components/Customs/Selects/SyAutocomplete/tests/SyAutocomplete.spec.ts +143 -0
- package/src/components/Customs/Selects/SyAutocomplete/utils/ariaManager.ts +14 -10
- package/src/components/Customs/Selects/SyInputSelect/SyInputSelect.stories.ts +4 -4
- package/src/components/Customs/Selects/SyInputSelect/SyInputSelect.vue +8 -9
- package/src/components/Customs/Selects/SyInputSelect/tests/SyInputSelect.spec.ts +10 -10
- package/src/components/Customs/Selects/SySelect/SySelect.vue +14 -11
- package/src/components/Customs/Selects/SySelect/tests/SySelect.spec.ts +54 -0
- package/src/components/Customs/SyCheckBoxGroup/SyCheckBoxGroup.vue +6 -9
- package/src/components/Customs/SyCheckbox/SyCheckbox.stories.ts +10 -16
- package/src/components/Customs/SyCheckbox/SyCheckbox.vue +16 -11
- package/src/components/Customs/SyCheckbox/accessibilite/Accessibility.mdx +35 -0
- package/src/components/Customs/SyCheckbox/tests/SyCheckbox.a11y.spec.ts +134 -2
- package/src/components/Customs/SyForm/SyForm.stories.ts +31 -5
- package/src/components/Customs/SyRadioGroup/SyRadioGroup.vue +4 -7
- package/src/components/Customs/SyTextField/SyTextField.mdx +1 -1
- package/src/components/Customs/SyTextField/SyTextField.stories.ts +29 -27
- package/src/components/Customs/SyTextField/SyTextField.vue +154 -157
- package/src/components/Customs/SyTextField/tests/SyTextField.a11y.spec.ts +32 -0
- package/src/components/Customs/SyTextField/tests/SyTextField.spec.ts +120 -11
- package/src/components/DatePicker/CalendarMode/DatePicker.stories.ts +62 -58
- package/src/components/DatePicker/CalendarMode/DatePicker.vue +330 -223
- package/src/components/DatePicker/CalendarMode/accessibilite/Accessibility.mdx +82 -0
- package/src/components/DatePicker/CalendarMode/tests/DatePicker.a11y.spec.ts +141 -0
- package/src/components/DatePicker/ComplexDatePicker/ComplexDatePicker.stories.ts +2 -56
- package/src/components/DatePicker/ComplexDatePicker/ComplexDatePicker.vue +195 -159
- package/src/components/DatePicker/ComplexDatePicker/accessibilite/Accessibility.mdx +76 -0
- package/src/components/DatePicker/ComplexDatePicker/tests/ComplexDatePicker.spec.ts +10 -10
- package/src/components/DatePicker/DatePickerValidationExample/CalendarMode.stories.ts +8 -8
- package/src/components/DatePicker/DatePickerValidationExample/ComplexDatePicker.stories.ts +106 -8
- package/src/components/DatePicker/DatePickerValidationExample/DateTextInput.stories.ts +12 -11
- package/src/components/DatePicker/DatePickerValidationExample/MultiMode.stories.ts +12 -12
- package/src/components/DatePicker/DateTextInput/DateRange.stories.ts +0 -12
- package/src/components/DatePicker/DateTextInput/DateTextInput.vue +63 -57
- package/src/components/DatePicker/DateTextInput/NoCalendar.stories.ts +3 -0
- package/src/components/DatePicker/DateTextInput/accessibilite/Accessibility.mdx +66 -0
- package/src/components/DatePicker/DateTextInput/tests/DateTextInput.spec.ts +52 -1
- package/src/components/DatePicker/composables/index.ts +1 -0
- package/src/components/DatePicker/composables/tests/useCalendarKeyboardNavigation.spec.ts +109 -65
- package/src/components/DatePicker/composables/tests/useDatePickerFocusTrap.spec.ts +138 -0
- package/src/components/DatePicker/composables/tests/useDateValidation.spec.ts +74 -18
- package/src/components/DatePicker/composables/tests/useInputBlurHandler.spec.ts +39 -0
- package/src/components/DatePicker/composables/tests/useManualDateValidation.spec.ts +91 -0
- package/src/components/DatePicker/composables/useCalendarKeyboardNavigation.ts +442 -36
- package/src/components/DatePicker/composables/useDatePickerFocusTrap.ts +92 -0
- package/src/components/DatePicker/composables/useDateTextField.ts +7 -6
- package/src/components/DatePicker/composables/useDateValidation.ts +36 -35
- package/src/components/DatePicker/composables/useInputBlurHandler.ts +3 -3
- package/src/components/DatePicker/composables/useManualDateValidation.ts +6 -2
- package/src/components/DiacriticPicker/accessibilite/Accessibility.mdx +76 -8
- package/src/components/HeaderBar/HeaderBar.stories.ts +14 -2
- package/src/components/Logo/accessibilite/Accessibility.mdx +73 -11
- package/src/components/LogoBrandSection/accessibilite/Accessibility.mdx +85 -9
- package/src/components/LunarCalendar/tests/LunarCalendar.spec.ts +3 -1
- package/src/components/LunarCalendar/useLunarCalendarValidation.ts +4 -5
- package/src/components/MonthPicker/tests/MonthPicker.spec.ts +2 -1
- package/src/components/MonthPicker/tests/__snapshots__/MonthPicker.spec.ts.snap +7 -7
- package/src/components/NirField/NirField.stories.ts +4 -0
- package/src/components/NirField/NirField.vue +64 -260
- package/src/components/NirField/accessibilite/Accessibility.mdx +2 -2
- package/src/components/NirField/locales.ts +1 -1
- package/src/components/NirField/tests/NirField.spec.ts +6 -0
- package/src/components/NirField/useNirValidation.ts +271 -0
- package/src/components/PasswordField/PasswordField.stories.ts +4 -4
- package/src/components/PasswordField/PasswordField.vue +18 -24
- package/src/components/PasswordField/tests/PasswordField.spec.ts +6 -3
- package/src/components/PeriodField/PeriodField.stories.ts +4 -4
- package/src/components/PeriodField/PeriodField.vue +57 -57
- package/src/components/PeriodField/__tests__/PeriodField.async.spec.ts +32 -0
- package/src/components/PeriodField/accessibilite/Accessibility.mdx +68 -8
- package/src/components/PeriodField/tests/PeriodField.spec.ts +28 -2
- package/src/components/PhoneField/PhoneField.vue +5 -6
- package/src/components/PhoneField/tests/PhoneField.spec.ts +1 -0
- package/src/components/RangeField/RangeField.vue +6 -0
- package/src/components/SyTextArea/SyTextArea.stories.ts +138 -2
- package/src/components/SyTextArea/SyTextArea.vue +53 -23
- package/src/components/SyTextArea/tests/SyTextArea.spec.ts +126 -3
- package/src/components/SyTextArea/useDefaultValidationRules.ts +74 -0
- package/src/components/Tables/SyServerTable/SyServerTable.mdx +25 -0
- package/src/components/Tables/SyServerTable/SyServerTable.stories.ts +673 -1
- package/src/components/Tables/SyServerTable/SyServerTable.vue +148 -91
- package/src/components/Tables/SyServerTable/tests/SyServerTable.a11y.spec.ts +58 -0
- package/src/components/Tables/SyServerTable/tests/SyServerTable.spec.ts +122 -0
- package/src/components/Tables/SyTable/SyTable.mdx +25 -0
- package/src/components/Tables/SyTable/SyTable.stories.ts +452 -1
- package/src/components/Tables/SyTable/SyTable.vue +130 -56
- package/src/components/Tables/SyTable/tests/SyTable.a11y.spec.ts +57 -0
- package/src/components/Tables/SyTable/tests/SyTable.spec.ts +108 -0
- package/src/components/Tables/common/SyTableFilter.vue +22 -2
- package/src/components/Tables/common/TableHeader.vue +5 -1
- package/src/components/Tables/common/filters/AutocompleteFilter.vue +160 -0
- package/src/components/Tables/common/filters/NumberFilter.vue +1 -1
- package/src/components/Tables/common/filters/SelectFilter.vue +10 -11
- package/src/components/Tables/common/filters/TextFilter.vue +1 -1
- package/src/components/Tables/common/filters/getFilterComponent.ts +8 -1
- package/src/components/Tables/common/filters/locales.ts +0 -1
- package/src/components/Tables/common/filters/tests/AutocompleteFilter.a11y.spec.ts +110 -0
- package/src/components/Tables/common/filters/tests/AutocompleteFilter.spec.ts +203 -0
- package/src/components/Tables/common/filters/tests/SelectFilter.a11y.spec.ts +104 -0
- package/src/components/Tables/common/filters/tests/SelectFilter.spec.ts +152 -16
- package/src/components/Tables/common/tableFilterUtils.ts +3 -0
- package/src/components/Tables/common/tableStyles.scss +48 -4
- package/src/components/Tables/common/tests/filterByRange.spec.ts +2 -1
- package/src/components/Tables/common/types.ts +13 -4
- package/src/components/Tables/common/useClickableTableRow.ts +103 -0
- package/src/components/Tables/common/usePagination.ts +13 -0
- package/src/components/Tables/common/usePinnedColumns.ts +237 -0
- package/src/components/Tables/common/useTableHeaders.ts +3 -3
- package/src/components/Tables/common/useTableRowCheckboxAccessibility.ts +41 -0
- package/src/composables/date/tests/useDatePickerAccessibility.spec.ts +2 -6
- package/src/composables/date/useDatePickerAccessibility.ts +42 -207
- package/src/composables/rules/tests/useFieldValidation.spec.ts +120 -120
- package/src/composables/rules/useFieldValidation.ts +34 -17
- package/src/composables/unifyValidation/tests/useCustomValidation.spec.ts +601 -0
- package/src/composables/unifyValidation/tests/useValidation.spec.ts +2048 -0
- package/src/composables/unifyValidation/tests/useVuetifyValidation.spec.ts +184 -0
- package/src/composables/unifyValidation/useCustomValidation.ts +95 -0
- package/src/composables/unifyValidation/useValidation.ts +190 -0
- package/src/composables/unifyValidation/useVuetifyValidation.ts +54 -0
- package/src/composables/useFormFieldErrorHandling.ts +4 -7
- package/src/composables/validation/tests/useFormValidation.spec.ts +14 -0
- package/src/composables/validation/tests/useValidation.spec.ts +116 -21
- package/src/composables/validation/useFormValidation.ts +20 -13
- package/src/composables/validation/useValidatable.ts +8 -1
- package/src/composables/validation/useValidation.ts +135 -99
- package/src/composantsVuetify/Introduction.mdx +48 -0
- package/src/composantsVuetify/VBtn/VBtn.mdx +72 -0
- package/src/composantsVuetify/VBtn/v-btn.stories.ts +121 -0
- package/src/composantsVuetify/VTooltip/VTooltip.mdx +32 -0
- package/src/composantsVuetify/VTooltip/v-tooltip.stories.ts +95 -0
- package/src/designTokens/tokens/cnam/cnamSemantic.ts +2 -2
- package/src/main.ts +0 -2
- package/src/stories/Components/Components.stories.ts +74 -9
- package/src/stories/Demarrer/Accueil.stories.ts +3 -3
- package/src/stories/GuideDuDev/Amelipro.mdx +15 -0
- package/src/stories/GuideDuDev/Amelipro.stories.ts +209 -0
- package/src/stories/GuideDuDev/vuetifyOptions.mdx +3 -3
- package/dist/SelectFilter-BioGT6Nn.js +0 -136
- package/dist/style.css +0 -1
- package/src/components/DatePicker/Accessibilite.mdx +0 -14
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { defineComponent, nextTick, ref } from 'vue'
|
|
3
|
+
import { mount } from '@vue/test-utils'
|
|
4
|
+
import type { ValidationRule } from 'vuetify'
|
|
5
|
+
import { useVuetifyValidation } from '../useVuetifyValidation'
|
|
6
|
+
|
|
7
|
+
/** Run a composable inside a mounted Vue component (needed for Vuetify's internal composable). */
|
|
8
|
+
function withSetup<T>(setup: () => T): { result: T, wrapper: ReturnType<typeof mount> } {
|
|
9
|
+
let result: T
|
|
10
|
+
const TestComponent = defineComponent({
|
|
11
|
+
setup() {
|
|
12
|
+
result = setup()
|
|
13
|
+
return {}
|
|
14
|
+
},
|
|
15
|
+
render: () => null,
|
|
16
|
+
})
|
|
17
|
+
const wrapper = mount(TestComponent)
|
|
18
|
+
return { result: result!, wrapper }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('useVuetifyValidation', () => {
|
|
22
|
+
const defaultArgs = () => ({
|
|
23
|
+
modelValue: ref<unknown>(''),
|
|
24
|
+
rules: ref<ValidationRule[]>([]),
|
|
25
|
+
disabled: ref(false),
|
|
26
|
+
errors: ref<string[]>([]),
|
|
27
|
+
error: ref(false),
|
|
28
|
+
errorMessages: ref<string[]>([]),
|
|
29
|
+
focused: ref(false),
|
|
30
|
+
maxErrors: ref(1),
|
|
31
|
+
name: ref('fieldName'),
|
|
32
|
+
label: ref('Mon label'),
|
|
33
|
+
readonly: ref(false),
|
|
34
|
+
validateOn: ref<'input' | 'blur' | 'submit'>('blur'),
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('returns a vuetify validator with a validate function', () => {
|
|
38
|
+
const args = defaultArgs()
|
|
39
|
+
const { result } = withSetup(() =>
|
|
40
|
+
useVuetifyValidation(
|
|
41
|
+
args.modelValue,
|
|
42
|
+
args.rules,
|
|
43
|
+
args.disabled,
|
|
44
|
+
args.errors,
|
|
45
|
+
args.error,
|
|
46
|
+
args.errorMessages,
|
|
47
|
+
args.focused,
|
|
48
|
+
args.maxErrors,
|
|
49
|
+
args.name,
|
|
50
|
+
args.label,
|
|
51
|
+
args.readonly,
|
|
52
|
+
args.validateOn,
|
|
53
|
+
),
|
|
54
|
+
)
|
|
55
|
+
expect(result).toBeDefined()
|
|
56
|
+
expect(typeof result.validate).toBe('function')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('isPristine is true before any validate() call', () => {
|
|
60
|
+
const args = defaultArgs()
|
|
61
|
+
args.rules.value = [(v: unknown) => !!v || 'Ce champ est requis']
|
|
62
|
+
const { result } = withSetup(() =>
|
|
63
|
+
useVuetifyValidation(
|
|
64
|
+
args.modelValue,
|
|
65
|
+
args.rules,
|
|
66
|
+
args.disabled,
|
|
67
|
+
args.errors,
|
|
68
|
+
args.error,
|
|
69
|
+
args.errorMessages,
|
|
70
|
+
args.focused,
|
|
71
|
+
args.maxErrors,
|
|
72
|
+
args.name,
|
|
73
|
+
args.label,
|
|
74
|
+
args.readonly,
|
|
75
|
+
args.validateOn,
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
expect(result.isPristine.value).toBe(true)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('errors are empty before validate() is called (isPristine guard)', async () => {
|
|
82
|
+
const args = defaultArgs()
|
|
83
|
+
args.rules.value = [(v: unknown) => !!v || 'Ce champ est requis']
|
|
84
|
+
withSetup(() =>
|
|
85
|
+
useVuetifyValidation(
|
|
86
|
+
args.modelValue,
|
|
87
|
+
args.rules,
|
|
88
|
+
args.disabled,
|
|
89
|
+
args.errors,
|
|
90
|
+
args.error,
|
|
91
|
+
args.errorMessages,
|
|
92
|
+
args.focused,
|
|
93
|
+
args.maxErrors,
|
|
94
|
+
args.name,
|
|
95
|
+
args.label,
|
|
96
|
+
args.readonly,
|
|
97
|
+
args.validateOn,
|
|
98
|
+
),
|
|
99
|
+
)
|
|
100
|
+
await nextTick()
|
|
101
|
+
expect(args.errors.value).toEqual([])
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('validate() with failing required rule populates errors', async () => {
|
|
105
|
+
const args = defaultArgs()
|
|
106
|
+
args.modelValue.value = ''
|
|
107
|
+
args.rules.value = [(v: unknown) => !!v || 'Ce champ est requis']
|
|
108
|
+
const { result } = withSetup(() =>
|
|
109
|
+
useVuetifyValidation(
|
|
110
|
+
args.modelValue,
|
|
111
|
+
args.rules,
|
|
112
|
+
args.disabled,
|
|
113
|
+
args.errors,
|
|
114
|
+
args.error,
|
|
115
|
+
args.errorMessages,
|
|
116
|
+
args.focused,
|
|
117
|
+
args.maxErrors,
|
|
118
|
+
args.name,
|
|
119
|
+
args.label,
|
|
120
|
+
args.readonly,
|
|
121
|
+
args.validateOn,
|
|
122
|
+
),
|
|
123
|
+
)
|
|
124
|
+
await result.validate()
|
|
125
|
+
await nextTick()
|
|
126
|
+
expect(args.errors.value).toContain('Ce champ est requis')
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('validate() with passing required rule keeps errors empty', async () => {
|
|
130
|
+
const args = defaultArgs()
|
|
131
|
+
args.modelValue.value = 'valid'
|
|
132
|
+
args.rules.value = [(v: unknown) => !!v || 'Ce champ est requis']
|
|
133
|
+
const { result } = withSetup(() =>
|
|
134
|
+
useVuetifyValidation(
|
|
135
|
+
args.modelValue,
|
|
136
|
+
args.rules,
|
|
137
|
+
args.disabled,
|
|
138
|
+
args.errors,
|
|
139
|
+
args.error,
|
|
140
|
+
args.errorMessages,
|
|
141
|
+
args.focused,
|
|
142
|
+
args.maxErrors,
|
|
143
|
+
args.name,
|
|
144
|
+
args.label,
|
|
145
|
+
args.readonly,
|
|
146
|
+
args.validateOn,
|
|
147
|
+
),
|
|
148
|
+
)
|
|
149
|
+
await result.validate()
|
|
150
|
+
await nextTick()
|
|
151
|
+
expect(args.errors.value).toEqual([])
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
it('validate() then fix value: errors are cleared on next validate()', async () => {
|
|
155
|
+
const args = defaultArgs()
|
|
156
|
+
args.modelValue.value = ''
|
|
157
|
+
args.rules.value = [(v: unknown) => !!v || 'Ce champ est requis']
|
|
158
|
+
const { result } = withSetup(() =>
|
|
159
|
+
useVuetifyValidation(
|
|
160
|
+
args.modelValue,
|
|
161
|
+
args.rules,
|
|
162
|
+
args.disabled,
|
|
163
|
+
args.errors,
|
|
164
|
+
args.error,
|
|
165
|
+
args.errorMessages,
|
|
166
|
+
args.focused,
|
|
167
|
+
args.maxErrors,
|
|
168
|
+
args.name,
|
|
169
|
+
args.label,
|
|
170
|
+
args.readonly,
|
|
171
|
+
args.validateOn,
|
|
172
|
+
),
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
await result.validate()
|
|
176
|
+
await nextTick()
|
|
177
|
+
expect(args.errors.value).toContain('Ce champ est requis')
|
|
178
|
+
|
|
179
|
+
args.modelValue.value = 'some input'
|
|
180
|
+
await result.validate()
|
|
181
|
+
await nextTick()
|
|
182
|
+
expect(args.errors.value).toEqual([])
|
|
183
|
+
})
|
|
184
|
+
})
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useValidation, type ValidationRule } from '@/composables/validation/useValidation'
|
|
2
|
+
import { useValidatable } from '@/composables/validation/useValidatable'
|
|
3
|
+
import { watch } from 'vue'
|
|
4
|
+
import type { Ref } from 'vue'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Interface between the validation entrypoint "useValidation" composable and the custom validation logic.
|
|
8
|
+
*/
|
|
9
|
+
export function useCustomValidation(
|
|
10
|
+
modelValue: Ref<unknown>,
|
|
11
|
+
customRules: Ref<ValidationRule[]> | undefined,
|
|
12
|
+
customWarningRules: Ref<ValidationRule[]> | undefined,
|
|
13
|
+
customSuccessRules: Ref<ValidationRule[]> | undefined,
|
|
14
|
+
errors: Ref<string[]>,
|
|
15
|
+
warnings: Ref<string[]>,
|
|
16
|
+
successes: Ref<string[]>,
|
|
17
|
+
showSuccessMessages: Ref<boolean>,
|
|
18
|
+
label: Ref<string>,
|
|
19
|
+
focused: Ref<boolean>,
|
|
20
|
+
isValidateOnBlur: Ref<boolean>,
|
|
21
|
+
disableErrorHandling: Ref<boolean>,
|
|
22
|
+
readonly?: Ref<boolean>,
|
|
23
|
+
disabled?: Ref<boolean>,
|
|
24
|
+
) {
|
|
25
|
+
let validator = useValidation({
|
|
26
|
+
showSuccessMessages: showSuccessMessages.value,
|
|
27
|
+
fieldIdentifier: label.value,
|
|
28
|
+
disableErrorHandling: disableErrorHandling.value,
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
watch(
|
|
32
|
+
() => [showSuccessMessages.value, label.value, customRules?.value, customWarningRules?.value, customSuccessRules?.value, disableErrorHandling.value],
|
|
33
|
+
() => {
|
|
34
|
+
validator = useValidation({
|
|
35
|
+
showSuccessMessages: showSuccessMessages.value,
|
|
36
|
+
fieldIdentifier: label.value,
|
|
37
|
+
disableErrorHandling: disableErrorHandling.value,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const isDirty = errors.value.length > 0 || warnings.value.length > 0 || successes.value.length > 0
|
|
41
|
+
if (isDirty) {
|
|
42
|
+
validate()
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
{ deep: true },
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
async function validate() {
|
|
49
|
+
if (readonly?.value || disabled?.value) {
|
|
50
|
+
errors.value = []
|
|
51
|
+
warnings.value = []
|
|
52
|
+
successes.value = []
|
|
53
|
+
return { hasError: false, hasWarning: false, hasSuccess: false, state: { errors: [] as string[], warnings: [] as string[], successes: [] as string[] } }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const result = await validator.validateField(
|
|
57
|
+
modelValue.value,
|
|
58
|
+
customRules?.value,
|
|
59
|
+
customWarningRules?.value,
|
|
60
|
+
customSuccessRules?.value,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
errors.value = result.state.errors
|
|
64
|
+
warnings.value = result.state.warnings
|
|
65
|
+
successes.value = result.state.successes
|
|
66
|
+
|
|
67
|
+
return result
|
|
68
|
+
}
|
|
69
|
+
useValidatable(
|
|
70
|
+
async () => {
|
|
71
|
+
const result = await validate()
|
|
72
|
+
return result.state.errors.length === 0
|
|
73
|
+
},
|
|
74
|
+
() => {
|
|
75
|
+
errors.value = []
|
|
76
|
+
warnings.value = []
|
|
77
|
+
successes.value = []
|
|
78
|
+
},
|
|
79
|
+
() => modelValue.value = undefined,
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
watch(focused, (newVal) => {
|
|
83
|
+
if (!newVal && !disableErrorHandling.value) {
|
|
84
|
+
validate()
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
watch(modelValue, () => {
|
|
89
|
+
if (!isValidateOnBlur.value && !disableErrorHandling.value) {
|
|
90
|
+
validate()
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
return { validate }
|
|
95
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import type { ValidationRule as SyValidationRule } from '@/composables/validation/useValidation'
|
|
2
|
+
import { computed, ref, toValue, type Ref } from 'vue'
|
|
3
|
+
import type { ValidationRule as VuetifyValidationRule } from 'vuetify'
|
|
4
|
+
import { useCustomValidation } from './useCustomValidation'
|
|
5
|
+
import { useVuetifyValidation as useVuetifyValidationComposable } from './useVuetifyValidation'
|
|
6
|
+
|
|
7
|
+
export interface FieldValidationProps {
|
|
8
|
+
modelValue?: unknown
|
|
9
|
+
readonly?: boolean
|
|
10
|
+
disabled?: boolean
|
|
11
|
+
required?: boolean
|
|
12
|
+
isValidateOnBlur?: boolean
|
|
13
|
+
showSuccessMessages?: boolean
|
|
14
|
+
disableErrorHandling?: boolean
|
|
15
|
+
// When true (Vuetify native mode), the controller should not handle errors/successes
|
|
16
|
+
useVuetifyValidation?: boolean
|
|
17
|
+
label: string
|
|
18
|
+
rules?: VuetifyValidationRule[]
|
|
19
|
+
customRules?: SyValidationRule[]
|
|
20
|
+
customWarningRules?: SyValidationRule[]
|
|
21
|
+
customSuccessRules?: SyValidationRule[]
|
|
22
|
+
errorMessages?: string[] | null
|
|
23
|
+
warningMessages?: string[] | null
|
|
24
|
+
successMessages?: string[] | null
|
|
25
|
+
hasError?: boolean
|
|
26
|
+
hasWarning?: boolean
|
|
27
|
+
hasSuccess?: boolean
|
|
28
|
+
maxErrors?: number
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Entrypoint to handle validation in fields components.
|
|
33
|
+
* It handles both Vuetify native validation (if useVuetifyValidation is true) and Synapse custom validation (if customRules are provided).
|
|
34
|
+
* It also provides a unified interface to handle errors, warnings and successes, and to trigger validation on demand.
|
|
35
|
+
*/
|
|
36
|
+
export const validationPropsDefaults = {
|
|
37
|
+
readonly: false,
|
|
38
|
+
disabled: false,
|
|
39
|
+
required: false,
|
|
40
|
+
isValidateOnBlur: true,
|
|
41
|
+
showSuccessMessages: true,
|
|
42
|
+
disableErrorHandling: false,
|
|
43
|
+
customRules: () => [],
|
|
44
|
+
customWarningRules: () => [],
|
|
45
|
+
customSuccessRules: () => [],
|
|
46
|
+
errorMessages: null,
|
|
47
|
+
warningMessages: null,
|
|
48
|
+
successMessages: null,
|
|
49
|
+
useVuetifyValidation: false,
|
|
50
|
+
hasError: false,
|
|
51
|
+
hasWarning: false,
|
|
52
|
+
hasSuccess: false,
|
|
53
|
+
maxErrors: 1,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function useValidation(params: {
|
|
57
|
+
modelValue: Ref<unknown>
|
|
58
|
+
readonly: Ref<boolean>
|
|
59
|
+
disabled: Ref<boolean>
|
|
60
|
+
required: Ref<boolean>
|
|
61
|
+
isValidateOnBlur: Ref<boolean>
|
|
62
|
+
showSuccessMessages: Ref<boolean>
|
|
63
|
+
disableErrorHandling: Ref<boolean>
|
|
64
|
+
label: Ref<string>
|
|
65
|
+
focused: Ref<boolean>
|
|
66
|
+
errorMessages?: Ref<string[] | null | undefined>
|
|
67
|
+
warningMessages?: Ref<string[] | null | undefined>
|
|
68
|
+
successMessages?: Ref<string[] | null | undefined>
|
|
69
|
+
hasErrorProp?: Ref<boolean>
|
|
70
|
+
hasWarningProp?: Ref<boolean>
|
|
71
|
+
hasSuccessProp?: Ref<boolean>
|
|
72
|
+
} & ({
|
|
73
|
+
useVuetifyValidation: true
|
|
74
|
+
rules: Ref<VuetifyValidationRule[] | undefined>
|
|
75
|
+
customRules?: never
|
|
76
|
+
customWarningRules?: never
|
|
77
|
+
customSuccessRules?: never
|
|
78
|
+
maxErrors?: Ref<number>
|
|
79
|
+
} | {
|
|
80
|
+
useVuetifyValidation: false
|
|
81
|
+
customRules: Ref<SyValidationRule[]>
|
|
82
|
+
customWarningRules?: Ref<SyValidationRule[]>
|
|
83
|
+
customSuccessRules?: Ref<SyValidationRule[]>
|
|
84
|
+
rules?: never
|
|
85
|
+
} | {
|
|
86
|
+
useVuetifyValidation: Ref<boolean>
|
|
87
|
+
customRules: Ref<SyValidationRule[]>
|
|
88
|
+
customWarningRules?: Ref<SyValidationRule[]>
|
|
89
|
+
customSuccessRules?: Ref<SyValidationRule[]>
|
|
90
|
+
rules: Ref<VuetifyValidationRule[] | undefined>
|
|
91
|
+
maxErrors?: Ref<number>
|
|
92
|
+
})) {
|
|
93
|
+
if (params.disableErrorHandling.value) {
|
|
94
|
+
return {
|
|
95
|
+
errors: ref<string[]>([]),
|
|
96
|
+
warnings: ref<string[]>([]),
|
|
97
|
+
successes: ref<string[]>([]),
|
|
98
|
+
hasError: computed(() => false),
|
|
99
|
+
hasWarning: computed(() => false),
|
|
100
|
+
hasSuccess: computed(() => false),
|
|
101
|
+
validate: async () => true,
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
const innerErrors = ref<string[]>([])
|
|
105
|
+
const innerWarnings = ref<string[]>([])
|
|
106
|
+
const innerSuccesses = ref<string[]>([])
|
|
107
|
+
|
|
108
|
+
let vuetifyValidator: ReturnType<typeof useVuetifyValidationComposable> | null = null
|
|
109
|
+
|
|
110
|
+
if (params.useVuetifyValidation !== false) {
|
|
111
|
+
vuetifyValidator = useVuetifyValidationComposable(
|
|
112
|
+
params.modelValue,
|
|
113
|
+
params.rules,
|
|
114
|
+
params.disabled,
|
|
115
|
+
innerErrors,
|
|
116
|
+
params.hasErrorProp || ref(false),
|
|
117
|
+
computed(() => params.errorMessages?.value || []),
|
|
118
|
+
params.focused,
|
|
119
|
+
params.maxErrors,
|
|
120
|
+
params.label,
|
|
121
|
+
params.label,
|
|
122
|
+
params.readonly,
|
|
123
|
+
computed(() => params.isValidateOnBlur.value ? 'blur' : 'input'),
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const customValidator = useCustomValidation(
|
|
128
|
+
params.modelValue,
|
|
129
|
+
params.customRules,
|
|
130
|
+
params.customWarningRules,
|
|
131
|
+
params.customSuccessRules,
|
|
132
|
+
innerErrors,
|
|
133
|
+
innerWarnings,
|
|
134
|
+
innerSuccesses,
|
|
135
|
+
params.showSuccessMessages,
|
|
136
|
+
params.label,
|
|
137
|
+
params.focused,
|
|
138
|
+
params.isValidateOnBlur,
|
|
139
|
+
params.disableErrorHandling,
|
|
140
|
+
params.readonly,
|
|
141
|
+
params.disabled,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
async function validate(): Promise<boolean> {
|
|
145
|
+
if (params.readonly.value || params.disabled.value || params.disableErrorHandling.value) {
|
|
146
|
+
innerErrors.value = []
|
|
147
|
+
innerWarnings.value = []
|
|
148
|
+
innerSuccesses.value = []
|
|
149
|
+
|
|
150
|
+
return true
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (toValue(params.useVuetifyValidation)) {
|
|
154
|
+
const result = await vuetifyValidator!.validate()
|
|
155
|
+
return result?.length === 0
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
else {
|
|
159
|
+
const result = await customValidator.validate()
|
|
160
|
+
return result.state.errors.length === 0
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const errors = computed(() => [...new Set([
|
|
165
|
+
...innerErrors.value,
|
|
166
|
+
...(params.errorMessages?.value || []),
|
|
167
|
+
])])
|
|
168
|
+
const warnings = computed(() => [...new Set([
|
|
169
|
+
...innerWarnings.value,
|
|
170
|
+
...(params.warningMessages?.value || []),
|
|
171
|
+
])])
|
|
172
|
+
const successes = computed(() => [...new Set([
|
|
173
|
+
...(params.showSuccessMessages.value ? innerSuccesses.value : []),
|
|
174
|
+
...(params.successMessages?.value || []),
|
|
175
|
+
])])
|
|
176
|
+
|
|
177
|
+
const hasError = computed(() => errors.value.length > 0 || params.hasErrorProp?.value)
|
|
178
|
+
const hasWarning = computed(() => warnings.value.length > 0 || params.hasWarningProp?.value)
|
|
179
|
+
const hasSuccess = computed(() => (successes.value.length > 0 && !hasError.value && !hasWarning.value) || params.hasSuccessProp?.value)
|
|
180
|
+
|
|
181
|
+
return {
|
|
182
|
+
errors,
|
|
183
|
+
warnings,
|
|
184
|
+
successes,
|
|
185
|
+
hasError,
|
|
186
|
+
hasWarning,
|
|
187
|
+
hasSuccess,
|
|
188
|
+
validate,
|
|
189
|
+
}
|
|
190
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { computed, reactive, watch, type Ref } from 'vue'
|
|
2
|
+
import type { ValidationRule } from 'vuetify'
|
|
3
|
+
import { useValidation } from 'vuetify/lib/composables/validation.mjs'
|
|
4
|
+
|
|
5
|
+
/** Interface between the validation entrypoint "useValidation" composable and the Vuetify validation logic. */
|
|
6
|
+
export function useVuetifyValidation(
|
|
7
|
+
modelValue: Ref<unknown>,
|
|
8
|
+
rules: Ref<ValidationRule[] | undefined>,
|
|
9
|
+
disabled: Ref<boolean>,
|
|
10
|
+
errors: Ref<string[]>,
|
|
11
|
+
error: Ref<boolean>,
|
|
12
|
+
errorMessages: Ref<string[]>,
|
|
13
|
+
focused: Ref<boolean>,
|
|
14
|
+
maxErrors: Ref<number> | undefined,
|
|
15
|
+
name: Ref<string>,
|
|
16
|
+
label: Ref<string>,
|
|
17
|
+
readonly: Ref<boolean>,
|
|
18
|
+
validateOn: Ref<'input' | 'blur' | 'submit'>,
|
|
19
|
+
) {
|
|
20
|
+
// The vuetify validation composable expects props to be passed as a single object, so we create a reactive proxified object to pass the relevant props and keep them reactive.
|
|
21
|
+
const proxifiedProps = reactive({
|
|
22
|
+
'disabled': computed(() => !!disabled.value),
|
|
23
|
+
'error': computed(() => !!error.value),
|
|
24
|
+
'errorMessages': computed(() => errorMessages.value),
|
|
25
|
+
'focused': computed(() => !!focused.value),
|
|
26
|
+
'maxErrors': computed(() => maxErrors?.value || 1),
|
|
27
|
+
'name': computed(() => name.value),
|
|
28
|
+
'label': computed(() => label.value),
|
|
29
|
+
'readonly': computed(() => !!readonly.value),
|
|
30
|
+
'rules': computed(() => rules.value || []),
|
|
31
|
+
'modelValue': computed({
|
|
32
|
+
get: () => modelValue.value,
|
|
33
|
+
set: (value: unknown) => { modelValue.value = value },
|
|
34
|
+
}),
|
|
35
|
+
'validateOn': computed(() => validateOn.value),
|
|
36
|
+
'validationValue': computed(() => modelValue.value),
|
|
37
|
+
'onUpdate:modelValue': (value: unknown) => {
|
|
38
|
+
modelValue.value = value
|
|
39
|
+
},
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const vuetifyValidator = useValidation(
|
|
43
|
+
proxifiedProps,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
watch (() => vuetifyValidator.errorMessages.value, (newVal) => {
|
|
47
|
+
if (vuetifyValidator.isPristine.value) {
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
errors.value = newVal
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
return vuetifyValidator
|
|
54
|
+
}
|
|
@@ -27,8 +27,8 @@ export interface UseFormFieldErrorHandlingReturn {
|
|
|
27
27
|
errors: Ref<string[]>
|
|
28
28
|
warnings: Ref<string[]>
|
|
29
29
|
successes: Ref<string[]>
|
|
30
|
-
validateField: (value: unknown) => boolean
|
|
31
|
-
validateOnSubmit: () => boolean
|
|
30
|
+
validateField: (value: unknown) => Promise<boolean>
|
|
31
|
+
validateOnSubmit: () => Promise<boolean>
|
|
32
32
|
checkErrorOnBlur: () => void
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -38,9 +38,6 @@ export const useFormFieldErrorHandling = (
|
|
|
38
38
|
emitUpdate?: () => void,
|
|
39
39
|
): UseFormFieldErrorHandlingReturn => {
|
|
40
40
|
const validation = useValidation({
|
|
41
|
-
customRules: props.customRules || [],
|
|
42
|
-
warningRules: props.customWarningRules || [],
|
|
43
|
-
successRules: props.customSuccessRules || [],
|
|
44
41
|
showSuccessMessages: props.showSuccessMessages ?? true,
|
|
45
42
|
fieldIdentifier: props.label,
|
|
46
43
|
disableErrorHandling: props.disableErrorHandling ?? false,
|
|
@@ -71,7 +68,7 @@ export const useFormFieldErrorHandling = (
|
|
|
71
68
|
: [],
|
|
72
69
|
)
|
|
73
70
|
|
|
74
|
-
const validateField = (value: unknown) => {
|
|
71
|
+
const validateField = async (value: unknown) => {
|
|
75
72
|
if (props.disableErrorHandling) {
|
|
76
73
|
validation.clearValidation()
|
|
77
74
|
return true
|
|
@@ -85,7 +82,7 @@ export const useFormFieldErrorHandling = (
|
|
|
85
82
|
return true
|
|
86
83
|
}
|
|
87
84
|
|
|
88
|
-
const result = validation.validateField(
|
|
85
|
+
const result = await validation.validateField(
|
|
89
86
|
value,
|
|
90
87
|
[...defaultRules.value, ...props.customRules!],
|
|
91
88
|
props.customWarningRules!,
|
|
@@ -10,6 +10,12 @@ let lastChildApi: ReturnType<typeof useValidatableComponent> | null = null
|
|
|
10
10
|
|
|
11
11
|
const ChildComponent = {
|
|
12
12
|
name: 'ValidatableChild',
|
|
13
|
+
props: {
|
|
14
|
+
label: {
|
|
15
|
+
type: String,
|
|
16
|
+
default: 'Child Field',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
13
19
|
setup() {
|
|
14
20
|
const api = useValidatableComponent()
|
|
15
21
|
lastChildApi = api
|
|
@@ -81,6 +87,7 @@ describe('useFormValidation', () => {
|
|
|
81
87
|
|
|
82
88
|
it('clearAll calls clearValidation on registered components and ignores missing or throwing ones', () => {
|
|
83
89
|
lastChildApi = null
|
|
90
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
84
91
|
|
|
85
92
|
const wrapper = mount(ParentWithForm)
|
|
86
93
|
const form = (wrapper.vm as { form: FormValidationApi }).form
|
|
@@ -102,6 +109,7 @@ describe('useFormValidation', () => {
|
|
|
102
109
|
const componentThrowing: ValidatableComponent = {
|
|
103
110
|
validateOnSubmit: vi.fn(() => true),
|
|
104
111
|
clearValidation: throwingClear,
|
|
112
|
+
$props: { label: 'Champ test clear' },
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
childApi.register(componentWithClear)
|
|
@@ -112,6 +120,8 @@ describe('useFormValidation', () => {
|
|
|
112
120
|
|
|
113
121
|
expect(clearSpy).toHaveBeenCalledTimes(1)
|
|
114
122
|
expect(throwingClear).toHaveBeenCalledTimes(1)
|
|
123
|
+
expect(warnSpy).toHaveBeenCalledWith('Error clearing validation for field: Champ test clear', expect.any(Error))
|
|
124
|
+
warnSpy.mockRestore()
|
|
115
125
|
})
|
|
116
126
|
|
|
117
127
|
it('clearAll returns early when there are no registered components', () => {
|
|
@@ -126,6 +136,7 @@ describe('useFormValidation', () => {
|
|
|
126
136
|
|
|
127
137
|
it('resetAll calls reset on registered components and ignores missing or throwing ones', () => {
|
|
128
138
|
lastChildApi = null
|
|
139
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
129
140
|
|
|
130
141
|
const wrapper = mount(ParentWithForm)
|
|
131
142
|
const form = (wrapper.vm as { form: FormValidationApi }).form
|
|
@@ -147,6 +158,7 @@ describe('useFormValidation', () => {
|
|
|
147
158
|
const componentThrowingReset: ValidatableComponent = {
|
|
148
159
|
validateOnSubmit: vi.fn(() => true),
|
|
149
160
|
reset: throwingReset,
|
|
161
|
+
$props: { label: 'Champ test reset' },
|
|
150
162
|
}
|
|
151
163
|
|
|
152
164
|
childApi.register(componentWithReset)
|
|
@@ -157,6 +169,8 @@ describe('useFormValidation', () => {
|
|
|
157
169
|
|
|
158
170
|
expect(resetSpy).toHaveBeenCalledTimes(1)
|
|
159
171
|
expect(throwingReset).toHaveBeenCalledTimes(1)
|
|
172
|
+
expect(warnSpy).toHaveBeenCalledWith('Error resetting field: Champ test reset', expect.any(Error))
|
|
173
|
+
warnSpy.mockRestore()
|
|
160
174
|
})
|
|
161
175
|
|
|
162
176
|
it('resetAll returns early when there are no registered components', () => {
|