feat(ui): add template validation for string collection items

This commit is contained in:
psychedelicious
2025-01-10 14:02:37 +10:00
parent 0f1e632117
commit 0b26bb1ca3

View File

@@ -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