From 58c21e7d909a9f750302ad957350a46114ab6c06 Mon Sep 17 00:00:00 2001 From: Victor Hugo Duran Santiago Date: Fri, 7 Jun 2024 17:01:05 -0600 Subject: [PATCH 1/2] Add validation on keyup for tag component in submission form --- .../ds-dynamic-form-ui/models/tag/dynamic-tag.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.ts index 7c3d8982e1a..e7119a424ec 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.ts @@ -184,7 +184,7 @@ export class DsDynamicTagComponent extends DsDynamicVocabularyComponent implemen * @param event the keyUp event */ onKeyUp(event) { - if (event.keyCode === 13 || event.keyCode === 188) { + if (event.keyCode === 13 || (event.key.includes(',') && event.keyCode === 188) || ((event.key as string).includes(';') && event.keyCode === 186) ) { event.preventDefault(); // Key: 'Enter' or ',' or ';' this.addTagsToChips(); From 8504d8d0dce8b784a50b08b07eb2a9b05195cc8a Mon Sep 17 00:00:00 2001 From: Victor Hugo Duran Santiago Date: Sun, 16 Jun 2024 16:14:19 -0600 Subject: [PATCH 2/2] UPDATE --- .../models/tag/dynamic-tag.component.spec.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.spec.ts b/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.spec.ts index a6a4c451700..2e5feaba079 100644 --- a/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.spec.ts +++ b/src/app/shared/form/builder/ds-dynamic-form-ui/models/tag/dynamic-tag.component.spec.ts @@ -22,10 +22,11 @@ import { mockDynamicFormValidationService } from '../../../../../testing/dynamic-form-mock-services'; -function createKeyUpEvent(key: number) { +function createKeyUpEvent(key: number, keyName: string) { /* eslint-disable no-empty,@typescript-eslint/no-empty-function */ const event = { - keyCode: key, preventDefault: () => { + keyCode: key, + key: keyName, preventDefault: () => { }, stopPropagation: () => { } }; @@ -257,7 +258,7 @@ describe('DsDynamicTagComponent test suite', () => { }); it('should add an item on ENTER or key press is \',\' or \';\'', fakeAsync(() => { - let event = createKeyUpEvent(13); + let event = createKeyUpEvent(13,'Enter'); tagComp.currentValue = 'test value'; tagFixture.detectChanges(); @@ -268,7 +269,7 @@ describe('DsDynamicTagComponent test suite', () => { expect(tagComp.model.value).toEqual(['test value']); expect(tagComp.currentValue).toBeNull(); - event = createKeyUpEvent(188); + event = createKeyUpEvent(188,','); tagComp.currentValue = 'test value'; tagFixture.detectChanges();