From 945b8147a0dc73b9671126997fb09cde197fae85 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Thu, 30 Nov 2023 15:48:54 -0600 Subject: [PATCH 1/5] Still not working --- .../work-form/work-form/work-form.component.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/app/record/components/work-form/work-form/work-form.component.ts b/src/app/record/components/work-form/work-form/work-form.component.ts index 1f82019b78..bd71f07d6d 100644 --- a/src/app/record/components/work-form/work-form/work-form.component.ts +++ b/src/app/record/components/work-form/work-form/work-form.component.ts @@ -52,7 +52,7 @@ import { SnackbarService } from 'src/app/cdk/snackbar/snackbar.service' import { WorkIdentifiers } from 'src/app/shared/validators/work-identifiers/work-identifiers.validator' import { workCitationValidator } from 'src/app/shared/validators/citation/work-citation.validator' import { translatedTitleValidator } from 'src/app/shared/validators/translated-title/translated-title.validator' -import { merge, Subject } from 'rxjs' +import { merge, Subject, of } from 'rxjs' import { RecordService } from 'src/app/core/record/record.service' @Component({ @@ -266,7 +266,17 @@ export class WorkFormComponent implements OnInit { formGroup: UntypedFormGroup, externalIdentifierType: string ): AsyncValidatorFn { - return (control: AbstractControl) => { + + if(externalIdentifierType === 'isbn') { + return (control: AbstractControl) => { + of(undefined) + .pipe(map( () => { + if(!(formGroup.controls.externalIdentifierId.value?.lenght == 10 || formGroup.controls.externalIdentifierId.value == 13)) {return { validFormat: true, }} + } + )) + } + } else { + return (control: AbstractControl) => { return this._workService .validateWorkIdTypes(externalIdentifierType, control.value) .pipe( @@ -313,6 +323,7 @@ export class WorkFormComponent implements OnInit { }) ) } + } } private checkWorkIdentifiersChanges( From 63b9d006b7662f805b0ac7cb85baf2741bf09396 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Thu, 30 Nov 2023 15:50:35 -0600 Subject: [PATCH 2/5] F --- .../work-form/work-form/work-form.component.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/app/record/components/work-form/work-form/work-form.component.ts b/src/app/record/components/work-form/work-form/work-form.component.ts index bd71f07d6d..a94cb98bfa 100644 --- a/src/app/record/components/work-form/work-form/work-form.component.ts +++ b/src/app/record/components/work-form/work-form/work-form.component.ts @@ -271,10 +271,13 @@ export class WorkFormComponent implements OnInit { return (control: AbstractControl) => { of(undefined) .pipe(map( () => { - if(!(formGroup.controls.externalIdentifierId.value?.lenght == 10 || formGroup.controls.externalIdentifierId.value == 13)) {return { validFormat: true, }} + if(!(formGroup.controls.externalIdentifierId.value?.lenght == 10 || formGroup.controls.externalIdentifierId.value == 13)) + { + return { validFormat: true, } + } } - )) - } + ) + )} } else { return (control: AbstractControl) => { return this._workService From 0109eea7f6b209d0f177f7597de6805afcaff0de Mon Sep 17 00:00:00 2001 From: amontenegro Date: Thu, 30 Nov 2023 16:18:29 -0600 Subject: [PATCH 3/5] x --- .../work-form/work-form.component.ts | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/app/record/components/work-form/work-form/work-form.component.ts b/src/app/record/components/work-form/work-form/work-form.component.ts index a94cb98bfa..f82e34bc70 100644 --- a/src/app/record/components/work-form/work-form/work-form.component.ts +++ b/src/app/record/components/work-form/work-form/work-form.component.ts @@ -52,7 +52,7 @@ import { SnackbarService } from 'src/app/cdk/snackbar/snackbar.service' import { WorkIdentifiers } from 'src/app/shared/validators/work-identifiers/work-identifiers.validator' import { workCitationValidator } from 'src/app/shared/validators/citation/work-citation.validator' import { translatedTitleValidator } from 'src/app/shared/validators/translated-title/translated-title.validator' -import { merge, Subject, of } from 'rxjs' +import { merge, Subject, of, EMPTY } from 'rxjs' import { RecordService } from 'src/app/core/record/record.service' @Component({ @@ -266,21 +266,13 @@ export class WorkFormComponent implements OnInit { formGroup: UntypedFormGroup, externalIdentifierType: string ): AsyncValidatorFn { - - if(externalIdentifierType === 'isbn') { - return (control: AbstractControl) => { - of(undefined) - .pipe(map( () => { - if(!(formGroup.controls.externalIdentifierId.value?.lenght == 10 || formGroup.controls.externalIdentifierId.value == 13)) - { - return { validFormat: true, } + return (control: AbstractControl) => { + if(externalIdentifierType === 'isbn') { + if(!(formGroup.controls.externalIdentifierId.value?.lenght === 10 || formGroup.controls.externalIdentifierId.value === 13)) { + return of({ validFormat: true, }) } - } - ) - )} - } else { - return (control: AbstractControl) => { - return this._workService + } else { + return this._workService .validateWorkIdTypes(externalIdentifierType, control.value) .pipe( map((value) => { @@ -326,7 +318,7 @@ export class WorkFormComponent implements OnInit { }) ) } - } + } } private checkWorkIdentifiersChanges( From af474510f07772df4433c574c1c1999d5e72df32 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Thu, 30 Nov 2023 16:35:16 -0600 Subject: [PATCH 4/5] Use the control.value to get the up to date value inserted by user --- .../components/work-form/work-form/work-form.component.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/record/components/work-form/work-form/work-form.component.ts b/src/app/record/components/work-form/work-form/work-form.component.ts index f82e34bc70..a8f6ec337e 100644 --- a/src/app/record/components/work-form/work-form/work-form.component.ts +++ b/src/app/record/components/work-form/work-form/work-form.component.ts @@ -266,10 +266,12 @@ export class WorkFormComponent implements OnInit { formGroup: UntypedFormGroup, externalIdentifierType: string ): AsyncValidatorFn { - return (control: AbstractControl) => { + return (control: AbstractControl) => { if(externalIdentifierType === 'isbn') { - if(!(formGroup.controls.externalIdentifierId.value?.lenght === 10 || formGroup.controls.externalIdentifierId.value === 13)) { + if(!(control.value?.length === 10 || control.value?.length === 13)) { return of({ validFormat: true, }) + } else { + return of({}) } } else { return this._workService @@ -317,8 +319,8 @@ export class WorkFormComponent implements OnInit { } }) ) + } } - } } private checkWorkIdentifiersChanges( From 61aa9cf4c4e97f4d737d387e1e011e83b9fd483d Mon Sep 17 00:00:00 2001 From: amontenegro Date: Thu, 30 Nov 2023 16:36:12 -0600 Subject: [PATCH 5/5] Remove unecesary import --- .../components/work-form/work-form/work-form.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/record/components/work-form/work-form/work-form.component.ts b/src/app/record/components/work-form/work-form/work-form.component.ts index a8f6ec337e..4d6e688efe 100644 --- a/src/app/record/components/work-form/work-form/work-form.component.ts +++ b/src/app/record/components/work-form/work-form/work-form.component.ts @@ -52,7 +52,7 @@ import { SnackbarService } from 'src/app/cdk/snackbar/snackbar.service' import { WorkIdentifiers } from 'src/app/shared/validators/work-identifiers/work-identifiers.validator' import { workCitationValidator } from 'src/app/shared/validators/citation/work-citation.validator' import { translatedTitleValidator } from 'src/app/shared/validators/translated-title/translated-title.validator' -import { merge, Subject, of, EMPTY } from 'rxjs' +import { merge, Subject, of } from 'rxjs' import { RecordService } from 'src/app/core/record/record.service' @Component({