feat(ui): validate string item lengths

This commit is contained in:
psychedelicious
2025-01-10 15:13:37 +10:00
parent 1ed70bb21e
commit 2d8443cc21
2 changed files with 12 additions and 1 deletions

View File

@@ -1029,6 +1029,8 @@
"collectionEmpty": "empty collection",
"collectionTooFewItems": "too few items, minimum {{minItems}}",
"collectionTooManyItems": "too many items, maximum {{maxItems}}",
"collectionStringTooLong": "too long, max {{maxLength}}",
"collectionStringTooShort": "too short, min {{minLength}}",
"collectionNumberGTMax": "{{value}} > {{maximum}} (inc max)",
"collectionNumberLTMin": "{{value}} < {{minimum}} (inc min)",
"collectionNumberGTExclusiveMax": "{{value}} >= {{exclusiveMaximum}} (exc max)",

View File

@@ -39,7 +39,7 @@ export const validateStringFieldCollectionValue = (
template: StringFieldCollectionInputTemplate
): string[] => {
const reasons: string[] = [];
const { minItems, maxItems } = template;
const { minItems, maxItems, minLength, maxLength } = template;
const count = value.length;
// Image collections may have min or max items to validate
@@ -55,6 +55,15 @@ export const validateStringFieldCollectionValue = (
reasons.push(t('parameters.invoke.collectionTooManyItems', { count, maxItems }));
}
for (const str of value) {
if (maxLength !== undefined && str.length > maxLength) {
reasons.push(t('parameters.invoke.collectionStringTooLong', { value, maxLength }));
}
if (minLength !== undefined && str.length < minLength) {
reasons.push(t('parameters.invoke.collectionStringTooShort', { value, minLength }));
}
}
return reasons;
};