@@ -6,104 +6,100 @@ import { useComponentUniqueId } from '@/utils/composables/useComponentUniqueId'
66import { useFieldValidation } from ' @/utils/composables/useFieldValidation'
77import { isValidEmail } from ' @/utils/utils'
88
9- const props = withDefaults (defineProps <{
10- /** Label to add above the field */
11- label? : string
12- /** Description to add below the input */
13- description? : string
14- /** Mark the field as disable */
15- disabled? : boolean
16- /**
17- * Placeholder text
18- *
19- * NOTE: this should be a translation key
20- */
21- placeholder? : string
22- /** Field is required and will be marked as invalid if empty */
23- required? : boolean
24- /**
25- * Mark the field as valid
26- *
27- * This can be used if the field requires some external validation. When not set or set to
28- * undefined this props is ignored.
29- *
30- * NOTE: this props is ignored when activate-validation is false
31- */
32- validMarker? : boolean | undefined
33- /**
34- * Valid message Message that will be added in green below the field once the validation has
35- * been done and the field is valid.
36- */
37- validMessage? : string
38- /**
39- * Mark the field as invalid
40- *
41- * This can be used if the field requires some external validation. When not set or set to
42- * undefined this props is ignored.
43- *
44- * NOTE: this props is ignored when activate-validation is false
45- */
46- invalidMarker? : boolean | undefined
47- /**
48- * Invalid message Message that will be added in red below the field once the validation has
49- * been done and the field is invalid.
50- *
51- * NOTE: this message is overwritten if the internal validation failed (not allow file type or
52- * file too big or required empty file)
53- */
54- invalidMessage? : string
55- /**
56- * Mark the field has validated.
57- *
58- * As long as the flag is false, no validation is run and no validation marks are set. Also the
59- * props is-invalid and is-valid are ignored.
60- */
61- activateValidation? : boolean
62- /**
63- * Validate function to run when the input changes The function should return an object of type
64- * `{valid: Boolean, invalidMessage: String}`. The `invalidMessage` string should be a
65- * translation key.
66- *
67- * NOTE: this function is called each time the field is modified
68- */
69- validate? : ((_value ? : string ) => { valid: boolean ; invalidMessage: string }) | undefined
70- dataCy? : string
71- }>(), {
72- validMarker: undefined ,
73- invalidMarker: undefined ,
74- })
9+ const props = withDefaults (
10+ defineProps <{
11+ /** Label to add above the field */
12+ label? : string
13+ /** Description to add below the input */
14+ description? : string
15+ /** Mark the field as disable */
16+ disabled? : boolean
17+ /**
18+ * Placeholder text
19+ *
20+ * NOTE: this should be a translation key
21+ */
22+ placeholder? : string
23+ /** Field is required and will be marked as invalid if empty */
24+ required? : boolean
25+ /**
26+ * Mark the field as valid
27+ *
28+ * This can be used if the field requires some external validation. When not set or set to
29+ * undefined this props is ignored.
30+ *
31+ * NOTE: this props is ignored when activate-validation is false
32+ */
33+ validMarker? : boolean | undefined
34+ /**
35+ * Valid message Message that will be added in green below the field once the validation has
36+ * been done and the field is valid.
37+ */
38+ validMessage? : string
39+ /**
40+ * Mark the field as invalid
41+ *
42+ * This can be used if the field requires some external validation. When not set or set to
43+ * undefined this props is ignored.
44+ *
45+ * NOTE: this props is ignored when activate-validation is false
46+ */
47+ invalidMarker? : boolean | undefined
48+ /**
49+ * Invalid message Message that will be added in red below the field once the validation has
50+ * been done and the field is invalid.
51+ *
52+ * NOTE: this message is overwritten if the internal validation failed (not allow file type
53+ * or file too big or required empty file)
54+ */
55+ invalidMessage? : string
56+ /**
57+ * Mark the field has validated.
58+ *
59+ * As long as the flag is false, no validation is run and no validation marks are set. Also
60+ * the props is-invalid and is-valid are ignored.
61+ */
62+ activateValidation? : boolean
63+ /**
64+ * Validate function to run when the input changes The function should return an object of
65+ * type `{valid: Boolean, invalidMessage: String}`. The `invalidMessage` string should be a
66+ * translation key.
67+ *
68+ * NOTE: this function is called each time the field is modified
69+ */
70+ validate? : ((_value ? : string ) => { valid: boolean ; invalidMessage: string }) | undefined
71+ dataCy? : string
72+ }>(),
73+ {
74+ validMarker: undefined ,
75+ invalidMarker: undefined ,
76+ }
77+ )
7578
76- const {
77- label,
78- description,
79- disabled,
80- placeholder,
81- dataCy,
82- } = toRefs (props )
79+ const { label, description, disabled, placeholder, dataCy } = toRefs (props )
8380
8481const inputEmailId = useComponentUniqueId (' email-input' )
8582
8683const model = defineModel <string >({ default: ' ' })
87- const emits = defineEmits ([' change' , ' validate' , ' focusin' , ' focusout' , ' keydown.enter' ])
84+ const emits = defineEmits <{
85+ change: [void ]
86+ validate: [isValid : boolean ]
87+ focusin: [void ]
88+ focusout: [void ]
89+ ' keydown.enter' : [void ]
90+ }>()
8891const { t } = useI18n ()
8992
9093const {
9194 value,
9295 validMarker : computedValidMarker,
9396 invalidMarker : computedInvalidMarker,
94- validMessage : computedValidMessage,
9597 invalidMessage : computedInvalidMessage,
96- required : computedRequired,
9798 onFocus,
98- } = useFieldValidation (
99- props ,
100- model ,
101- emits as (_event : string , ... _args : unknown []) => void ,
102- {
103- customValidate: validateEmail ,
104- requiredInvalidMessage: ' no_email' ,
105- }
106- )
99+ } = useFieldValidation (props , model , emits , {
100+ customValidate: validateEmail ,
101+ requiredInvalidMessage: ' no_email' ,
102+ })
107103
108104const emailInputElement = useTemplateRef <HTMLInputElement >(' emailInputElement' )
109105
@@ -129,7 +125,7 @@ defineExpose({ focus })
129125 <label
130126 v-if =" label"
131127 class =" mb-2"
132- :class =" { 'fw-bolder': computedRequired }"
128+ :class =" { 'fw-bolder': required }"
133129 :for =" inputEmailId"
134130 data-cy =" email-input-label"
135131 >
@@ -146,7 +142,7 @@ defineExpose({ focus })
146142 }"
147143 type =" email"
148144 class =" form-control"
149- :required =" computedRequired "
145+ :required =" required "
150146 :placeholder =" placeholder ? t(placeholder) : ''"
151147 data-cy =" email-input"
152148 @focusin =" onFocus($event, true)"
@@ -161,11 +157,11 @@ defineExpose({ focus })
161157 {{ t(computedInvalidMessage) }}
162158 </div >
163159 <div
164- v-if =" computedValidMessage "
160+ v-if =" validMessage "
165161 class =" valid-feedback"
166162 data-cy =" email-input-valid-feedback"
167163 >
168- {{ t(computedValidMessage ) }}
164+ {{ t(validMessage ) }}
169165 </div >
170166 <div
171167 v-if =" description"
0 commit comments