mirror of
https://github.com/invoke-ai/InvokeAI.git
synced 2026-02-10 08:45:25 -05:00
feat(ui): add template validation for string collection items
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
isStringFieldCollectionInputInstance,
|
||||
isStringFieldCollectionInputTemplate,
|
||||
} from 'features/nodes/types/field';
|
||||
import { isNil } from 'lodash-es';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
export const useFieldIsInvalid = (nodeId: string, fieldName: string) => {
|
||||
@@ -63,6 +64,16 @@ export const useFieldIsInvalid = (nodeId: string, fieldName: string) => {
|
||||
if (template.maxItems !== undefined && field.value.length > template.maxItems) {
|
||||
return true;
|
||||
}
|
||||
if (field.value) {
|
||||
for (const str of field.value) {
|
||||
if (!isNil(template.maxLength) && str.length > template.maxLength) {
|
||||
return true;
|
||||
}
|
||||
if (!isNil(template.minLength) && str.length < template.minLength) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Integer collections may have min or max item counts
|
||||
|
||||
Reference in New Issue
Block a user