1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 export const ERROR_MESSAGE = 'Maximum string length of this field is: ';
6 export const DEFAULT_MAX_VALUE = 60;
8 interface MaxLengthProps {
9 maxLengthValue: number;
10 defaultErrorMessage: string;
13 // TODO types for maxLength
14 export const maxLength: any = (maxLengthValue = DEFAULT_MAX_VALUE, errorMessage = ERROR_MESSAGE) => {
15 return (value: string) => {
17 return value && value.length <= maxLengthValue ? undefined : `${errorMessage || ERROR_MESSAGE} ${maxLengthValue}`;