@@ -4,7 +4,7 @@ import { Utils } from '@labkey/api';
44
55import { Modal } from '../../Modal' ;
66
7- import { MAX_VALID_TEXT_CHOICES } from './constants' ;
7+ import { MAX_TEXT_CHOICE_VALUE_LENGTH , MAX_VALID_TEXT_CHOICES } from './constants' ;
88import { getValidValuesFromArray } from './models' ;
99
1010interface Props {
@@ -22,27 +22,31 @@ export const TextChoiceAddValuesModal: FC<Props> = memo(props => {
2222 return valueStr ?. trim ( ) . length > 0 ? getValidValuesFromArray ( valueStr . split ( '\n' ) . map ( v => v . trim ( ) ) ) : [ ] ;
2323 } , [ valueStr ] ) ;
2424 const maxValuesToAdd = useMemo ( ( ) => maxValueCount - initialValueCount , [ initialValueCount ] ) ;
25+ const tooLongValue = useMemo ( ( ) => parsedValues . find ( v => v . length > MAX_TEXT_CHOICE_VALUE_LENGTH ) , [ parsedValues ] ) ;
2526 const hasFieldName = useMemo ( ( ) => fieldName ?. length > 0 , [ fieldName ] ) ;
2627 const onChange = useCallback ( evt => {
2728 setValueStr ( evt . target . value ) ;
2829 } , [ ] ) ;
2930 const onConfirm = useCallback ( ( ) => {
30- if ( parsedValues . length <= maxValuesToAdd ) {
31+ if ( parsedValues . length <= maxValuesToAdd && ! tooLongValue ) {
3132 onApply ( parsedValues ) ;
3233 }
33- } , [ parsedValues , maxValuesToAdd , onApply ] ) ;
34- const canConfirm = parsedValues . length > 0 && parsedValues . length <= maxValuesToAdd ;
34+ } , [ parsedValues , maxValuesToAdd , tooLongValue , onApply ] ) ;
35+ const canConfirm = parsedValues . length > 0 && parsedValues . length <= maxValuesToAdd && ! tooLongValue ;
3536 const title = `Add Text Choice Values${ hasFieldName ? ' for ' + fieldName : '' } ` ;
3637 const valueNoun = Utils . pluralize ( maxValuesToAdd , 'value' , 'values' ) ;
3738 return (
3839 < Modal canConfirm = { canConfirm } confirmText = "Apply" onCancel = { onCancel } onConfirm = { onConfirm } title = { title } >
3940 < p > Enter each value on a new line. { valueNoun } can be added.</ p >
4041 < textarea
41- rows = { 8 }
42- cols = { 50 }
42+ aria-label = "Text choice values"
43+ aria-describedby = { tooLongValue ? 'text-choice-length-error' : undefined }
44+ aria-invalid = { ! ! tooLongValue }
4345 className = "form-control textarea-fullwidth"
44- placeholder = "Enter new values..."
46+ cols = { 50 }
4547 onChange = { onChange }
48+ placeholder = "Enter new values..."
49+ rows = { 8 }
4650 value = { valueStr }
4751 />
4852 < div
@@ -52,6 +56,12 @@ export const TextChoiceAddValuesModal: FC<Props> = memo(props => {
5256 >
5357 { parsedValues . length === 1 ? '1 new value provided.' : `${ parsedValues . length } new values provided.` }
5458 </ div >
59+ { tooLongValue && (
60+ < div className = "domain-text-choices-error" id = "text-choice-length-error" role = "alert" >
61+ Value exceeds maximum of { MAX_TEXT_CHOICE_VALUE_LENGTH } characters: "
62+ { tooLongValue . substring ( 0 , 50 ) } ..."
63+ </ div >
64+ ) }
5565 </ Modal >
5666 ) ;
5767} ) ;
0 commit comments