18874: Add 'services/workbench2/' from commit 'f6f88d9ca9cdeeeebfadcfe999789bfb9f69e5c6'
[arvados.git] / services / workbench2 / src / validators / max-length.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 export const ERROR_MESSAGE = 'Maximum string length of this field is: ';
6 export const DEFAULT_MAX_VALUE = 60;
7
8 export const maxLength: any = (maxLengthValue = DEFAULT_MAX_VALUE, errorMessage = ERROR_MESSAGE) => {
9     return (value: string) => {
10         if (value) {
11             return  value && value.length <= maxLengthValue ? undefined : `${errorMessage || ERROR_MESSAGE} ${maxLengthValue}`;
12         }
13
14         return undefined;
15     };
16 };