@streamscloud/kit 0.43.0 → 0.44.0
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.
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { ValidationLocalization } from './validation-localization';
|
|
2
2
|
import * as yup from 'yup';
|
|
3
|
+
const isEmptyOrHasContent = (value) => !value || value.trim().length > 0;
|
|
3
4
|
/** Value-level rules of `textValidationSchema`. Judges a real value — `null` / `undefined` are decided by the schema modifiers the caller adds. */
|
|
4
5
|
export const isValidText = (value, rules) => {
|
|
5
|
-
return value.length >= rules.minLength && value.length <= rules.maxLength;
|
|
6
|
+
return isEmptyOrHasContent(value) && value.length >= rules.minLength && value.length <= rules.maxLength;
|
|
6
7
|
};
|
|
7
8
|
/** Value-level rules of `formattedTextValidationSchema` — `isValidText` plus the format, which an empty value skips. */
|
|
8
9
|
export const isValidFormattedText = (value, rules) => {
|
|
@@ -10,7 +11,7 @@ export const isValidFormattedText = (value, rules) => {
|
|
|
10
11
|
};
|
|
11
12
|
export const textValidationSchema = (rules) => {
|
|
12
13
|
const msg = new ValidationLocalization();
|
|
13
|
-
const schema = yup.string().max(rules.maxLength, msg.maxLength(rules.maxLength));
|
|
14
|
+
const schema = yup.string().test('whitespace-only', msg.whitespaceOnly, isEmptyOrHasContent).max(rules.maxLength, msg.maxLength(rules.maxLength));
|
|
14
15
|
if (rules.minLength === 0) {
|
|
15
16
|
return schema;
|
|
16
17
|
}
|
|
@@ -24,6 +24,9 @@ export class ValidationLocalization {
|
|
|
24
24
|
get maxItems() {
|
|
25
25
|
return loc.maxItems[AppLocale.current];
|
|
26
26
|
}
|
|
27
|
+
get whitespaceOnly() {
|
|
28
|
+
return loc.whitespaceOnly[AppLocale.current];
|
|
29
|
+
}
|
|
27
30
|
get badFormat() {
|
|
28
31
|
return loc.badFormat[AppLocale.current];
|
|
29
32
|
}
|
|
@@ -64,6 +67,10 @@ const loc = {
|
|
|
64
67
|
en: (count) => `Must contain at most ${count} item${count === 1 ? '' : 's'}`,
|
|
65
68
|
no: (count) => `Kan ikke inneholde mer enn ${count} element${count === 1 ? '' : 'er'}`
|
|
66
69
|
},
|
|
70
|
+
whitespaceOnly: {
|
|
71
|
+
en: 'This field cannot contain only spaces',
|
|
72
|
+
no: 'Dette feltet kan ikke bestå av bare mellomrom'
|
|
73
|
+
},
|
|
67
74
|
badFormat: {
|
|
68
75
|
en: 'Invalid format',
|
|
69
76
|
no: 'Ugyldig format'
|