diff options
author | 2021-09-13 14:45:46 +0200 | |
---|---|---|
committer | 2021-09-13 14:45:46 +0200 | |
commit | 537697a6e9757f118d09d9e76362ba1ff617e2c6 (patch) | |
tree | bc55447115e385137684e84697a8c15d2199b8d5 /src/helpers/validation-helpers.js | |
parent | Bumped up version to: 5.6.3-nightly.0 [skip ci] (diff) | |
download | ferdium-app-537697a6e9757f118d09d9e76362ba1ff617e2c6.tar.gz ferdium-app-537697a6e9757f118d09d9e76362ba1ff617e2c6.tar.zst ferdium-app-537697a6e9757f118d09d9e76362ba1ff617e2c6.zip |
chore: upgrade intl dependencies (#1920)
Diffstat (limited to 'src/helpers/validation-helpers.js')
-rw-r--r-- | src/helpers/validation-helpers.js | 50 |
1 files changed, 37 insertions, 13 deletions
diff --git a/src/helpers/validation-helpers.js b/src/helpers/validation-helpers.js index 116f19905..569b13bb0 100644 --- a/src/helpers/validation-helpers.js +++ b/src/helpers/validation-helpers.js | |||
@@ -4,35 +4,41 @@ import isEmail from 'validator/lib/isEmail'; | |||
4 | const messages = defineMessages({ | 4 | const messages = defineMessages({ |
5 | required: { | 5 | required: { |
6 | id: 'validation.required', | 6 | id: 'validation.required', |
7 | defaultMessage: '!!!Field is required', | 7 | defaultMessage: 'Field is required', |
8 | }, | 8 | }, |
9 | email: { | 9 | email: { |
10 | id: 'validation.email', | 10 | id: 'validation.email', |
11 | defaultMessage: '!!!Email not valid', | 11 | defaultMessage: 'Email not valid', |
12 | }, | 12 | }, |
13 | url: { | 13 | url: { |
14 | id: 'validation.url', | 14 | id: 'validation.url', |
15 | defaultMessage: '!!!Not a valid URL', | 15 | defaultMessage: 'Not a valid URL', |
16 | }, | 16 | }, |
17 | minLength: { | 17 | minLength: { |
18 | id: 'validation.minLength', | 18 | id: 'validation.minLength', |
19 | defaultMessage: '!!!Too few characters', | 19 | defaultMessage: 'Too few characters', |
20 | }, | 20 | }, |
21 | oneRequired: { | 21 | oneRequired: { |
22 | id: 'validation.oneRequired', | 22 | id: 'validation.oneRequired', |
23 | defaultMessage: '!!!At least one is required', | 23 | defaultMessage: 'At least one is required', |
24 | }, | 24 | }, |
25 | }); | 25 | }); |
26 | 26 | ||
27 | export function required({ field }) { | 27 | export function required({ field }) { |
28 | const isValid = (field.value.trim() !== ''); | 28 | const isValid = field.value.trim() !== ''; |
29 | return [isValid, window.ferdi.intl.formatMessage(messages.required, { field: field.label })]; | 29 | return [ |
30 | isValid, | ||
31 | window.ferdi.intl.formatMessage(messages.required, { field: field.label }), | ||
32 | ]; | ||
30 | } | 33 | } |
31 | 34 | ||
32 | export function email({ field }) { | 35 | export function email({ field }) { |
33 | const value = field.value.trim(); | 36 | const value = field.value.trim(); |
34 | const isValid = isEmail(value); | 37 | const isValid = isEmail(value); |
35 | return [isValid, window.ferdi.intl.formatMessage(messages.email, { field: field.label })]; | 38 | return [ |
39 | isValid, | ||
40 | window.ferdi.intl.formatMessage(messages.email, { field: field.label }), | ||
41 | ]; | ||
36 | } | 42 | } |
37 | 43 | ||
38 | export function url({ field }) { | 44 | export function url({ field }) { |
@@ -41,12 +47,19 @@ export function url({ field }) { | |||
41 | 47 | ||
42 | if (value !== '') { | 48 | if (value !== '') { |
43 | // eslint-disable-next-line | 49 | // eslint-disable-next-line |
44 | isValid = Boolean(value.match(/(^|[\s.:;?\-\]<(])(https?:\/\/[-\w;/?:@&=+$|_.!~*|'()[\]%#,☺]+[\w/#](\(\))?)(?=$|[\s',|().:;?\-[\]>)])/i)); | 50 | isValid = Boolean( |
51 | value.match( | ||
52 | /(^|[\s.:;?\-\]<(])(https?:\/\/[-\w;/?:@&=+$|_.!~*|'()[\]%#,☺]+[\w/#](\(\))?)(?=$|[\s',|().:;?\-[\]>)])/i, | ||
53 | ), | ||
54 | ); | ||
45 | } else { | 55 | } else { |
46 | isValid = true; | 56 | isValid = true; |
47 | } | 57 | } |
48 | 58 | ||
49 | return [isValid, window.ferdi.intl.formatMessage(messages.url, { field: field.label })]; | 59 | return [ |
60 | isValid, | ||
61 | window.ferdi.intl.formatMessage(messages.url, { field: field.label }), | ||
62 | ]; | ||
50 | } | 63 | } |
51 | 64 | ||
52 | export function minLength(length) { | 65 | export function minLength(length) { |
@@ -55,13 +68,24 @@ export function minLength(length) { | |||
55 | if (field.touched) { | 68 | if (field.touched) { |
56 | isValid = field.value.length >= length; | 69 | isValid = field.value.length >= length; |
57 | } | 70 | } |
58 | return [isValid, window.ferdi.intl.formatMessage(messages.minLength, { field: field.label, length })]; | 71 | return [ |
72 | isValid, | ||
73 | window.ferdi.intl.formatMessage(messages.minLength, { | ||
74 | field: field.label, | ||
75 | length, | ||
76 | }), | ||
77 | ]; | ||
59 | }; | 78 | }; |
60 | } | 79 | } |
61 | 80 | ||
62 | export function oneRequired(targets) { | 81 | export function oneRequired(targets) { |
63 | return ({ field, form }) => { | 82 | return ({ field, form }) => { |
64 | const invalidFields = targets.filter((target) => form.$(target).value === ''); | 83 | const invalidFields = targets.filter(target => form.$(target).value === ''); |
65 | return [targets.length !== invalidFields.length, window.ferdi.intl.formatMessage(messages.required, { field: field.label })]; | 84 | return [ |
85 | targets.length !== invalidFields.length, | ||
86 | window.ferdi.intl.formatMessage(messages.required, { | ||
87 | field: field.label, | ||
88 | }), | ||
89 | ]; | ||
66 | }; | 90 | }; |
67 | } | 91 | } |