(fieldName: string, schema_0: PrimitiveSchemaDefinition)
| 272 | } |
| 273 | }, [schemaFields, formValues]); |
| 274 | function validateMultiSelect(fieldName: string, schema_0: PrimitiveSchemaDefinition) { |
| 275 | if (!isMultiSelectEnumSchema(schema_0)) return; |
| 276 | const selected = formValues[fieldName] as string[] | undefined ?? []; |
| 277 | const fieldRequired = schemaFields.find(f => f.name === fieldName)?.isRequired ?? false; |
| 278 | const min = schema_0.minItems; |
| 279 | const max = schema_0.maxItems; |
| 280 | // Skip minItems check when field is optional and unset |
| 281 | if (min !== undefined && selected.length < min && (selected.length > 0 || fieldRequired)) { |
| 282 | updateValidationError(fieldName, `Select at least ${min} ${plural(min, 'item')}`); |
| 283 | } else if (max !== undefined && selected.length > max) { |
| 284 | updateValidationError(fieldName, `Select at most ${max} ${plural(max, 'item')}`); |
| 285 | } else { |
| 286 | updateValidationError(fieldName); |
| 287 | } |
| 288 | } |
| 289 | function handleNavigation(direction: 'up' | 'down'): void { |
| 290 | // Collapse accordion and validate on navigate away |
| 291 | if (currentField && isMultiSelectEnumSchema(currentField.schema)) { |
no test coverage detected