codeforlife 2.6.4 → 2.6.5
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/src/components/form/TextField.tsx +25 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [2.6.5](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.4...v2.6.5) (2025-01-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* unique values ([#74](https://github.com/ocadotechnology/codeforlife-package-javascript/issues/74)) ([1d183d2](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/1d183d2806a7aa8ba98e78bf8a3fa9927ff37389))
|
|
7
|
+
|
|
1
8
|
## [2.6.4](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.3...v2.6.4) (2025-01-10)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -30,6 +30,8 @@ export type TextFieldProps = Omit<
|
|
|
30
30
|
validateOptions?: ValidateOptions
|
|
31
31
|
dirty?: boolean
|
|
32
32
|
split?: string | RegExp
|
|
33
|
+
unique?: boolean
|
|
34
|
+
uniqueCaseInsensitive?: boolean
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
// https://formik.org/docs/examples/with-material-ui
|
|
@@ -40,6 +42,8 @@ const TextField: FC<TextFieldProps> = ({
|
|
|
40
42
|
type = "text",
|
|
41
43
|
required = false,
|
|
42
44
|
dirty = false,
|
|
45
|
+
unique = false,
|
|
46
|
+
uniqueCaseInsensitive = false,
|
|
43
47
|
split,
|
|
44
48
|
validateOptions,
|
|
45
49
|
...otherTextFieldProps
|
|
@@ -49,7 +53,27 @@ const TextField: FC<TextFieldProps> = ({
|
|
|
49
53
|
const dotPath = name.split(".")
|
|
50
54
|
|
|
51
55
|
let _schema: Schema = schema
|
|
52
|
-
if (split)
|
|
56
|
+
if (split) {
|
|
57
|
+
_schema = YupArray().of(_schema)
|
|
58
|
+
if (unique || uniqueCaseInsensitive) {
|
|
59
|
+
_schema = _schema.test({
|
|
60
|
+
message: "cannot have duplicates",
|
|
61
|
+
test: values => {
|
|
62
|
+
if (Array.isArray(values) && values.length >= 2) {
|
|
63
|
+
return (
|
|
64
|
+
new Set(
|
|
65
|
+
uniqueCaseInsensitive && typeof values[0] === "string"
|
|
66
|
+
? values.map(value => value.toLowerCase())
|
|
67
|
+
: values,
|
|
68
|
+
).size === values.length
|
|
69
|
+
)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return true
|
|
73
|
+
},
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
}
|
|
53
77
|
if (required) {
|
|
54
78
|
_schema = _schema.required()
|
|
55
79
|
if (split) _schema = (_schema as ArraySchema<string[], any>).min(1)
|