diff --git a/src/common/components/textInput/TextInput.tsx b/src/common/components/textInput/TextInput.tsx index 2471c4e01..a33823ec3 100644 --- a/src/common/components/textInput/TextInput.tsx +++ b/src/common/components/textInput/TextInput.tsx @@ -9,6 +9,7 @@ import { getInputErrorText } from '../../utils/form'; type PropTypes = { name: string; label?: string; + maxLength?: number | undefined; disabled?: boolean; required?: boolean; readOnly?: boolean; @@ -23,6 +24,7 @@ type PropTypes = { const TextInput: React.FC> = ({ name, label, + maxLength = undefined, disabled, tooltip, required, @@ -48,6 +50,7 @@ const TextInput: React.FC> = ({ className={className} label={label || t(`hankeForm:labels:${name}`)} value={value || ''} + maxLength={maxLength} helperText={helperText} placeholder={placeholder} errorText={getInputErrorText(t, error)} diff --git a/src/domain/hanke/edit/HankeForm.test.tsx b/src/domain/hanke/edit/HankeForm.test.tsx index 77bf5b64e..2810ba916 100644 --- a/src/domain/hanke/edit/HankeForm.test.tsx +++ b/src/domain/hanke/edit/HankeForm.test.tsx @@ -119,6 +119,23 @@ describe('HankeForm', () => { expect(screen.getByTestId(FORMFIELD.KUVAUS)).toHaveValue(hankkeenKuvaus); }); + test('Hanke nimi should be limited to 100 characters and not exceed the limit with additional characters', async () => { + const { user } = render(); + const initialName = 'b'.repeat(90); + + fireEvent.change(screen.getByRole('textbox', { name: /hankkeen nimi/i }), { + target: { value: initialName }, + }); + + await user.type( + screen.getByRole('textbox', { name: /hankkeen nimi/i }), + 'additional_characters', + ); + + const result = screen.getByRole('textbox', { name: /hankkeen nimi/i }); + expect(result).toHaveValue(initialName.concat('additional')); + }); + test('Yhteystiedot can be filled', async () => { const { user } = await setupYhteystiedotPage(); diff --git a/src/domain/hanke/edit/HankeFormPerustiedot.tsx b/src/domain/hanke/edit/HankeFormPerustiedot.tsx index 789f2ae5c..de4546ee9 100644 --- a/src/domain/hanke/edit/HankeFormPerustiedot.tsx +++ b/src/domain/hanke/edit/HankeFormPerustiedot.tsx @@ -51,7 +51,7 @@ const HankeFormPerustiedot: React.FC> = ({

{t('form:requiredInstruction')}

- +