Skip to content

Commit 2cdec65

Browse files
authored
Merge pull request #26 from workfloworchestrator/1711-Pydanticforms-basic--Multiselect-checkboxes
add array validator
2 parents 238af53 + 62b905c commit 2cdec65

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

frontend/packages/pydantic-forms/src/components/defaultComponentMatchers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ const defaultComponentMatchers: PydanticComponentMatcher[] = [
139139
field.options.length <= 5
140140
);
141141
},
142+
validator: zodValidationPresets.array,
142143
},
143144
];
144145

frontend/packages/pydantic-forms/src/components/zodValidations.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,25 @@ export const zodValidationPresets: PydanticFormZodValidationPresets = {
110110

111111
return validationRule;
112112
},
113+
array: (field) => {
114+
const { minimum, maximum } = field?.validation ?? {};
115+
116+
let arraySchema = z.array(z.boolean());
117+
118+
if (minimum) {
119+
arraySchema = arraySchema.min(
120+
minimum,
121+
`Dit veld heeft een minimum waarde van ${minimum}`,
122+
);
123+
}
124+
125+
if (maximum) {
126+
arraySchema = arraySchema.max(
127+
maximum,
128+
`Dit veld heeft een maximum waarde van ${maximum}`,
129+
);
130+
}
131+
132+
return arraySchema;
133+
},
113134
};

0 commit comments

Comments
 (0)