mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-04-23 03:00:31 -04:00
feat(ui): validate string item lengths
This commit is contained in:
@@ -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)",
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user