Skip to content

Commit

Permalink
Merge pull request #1152 from ORCID/fix-default-form-values
Browse files Browse the repository at this point in the history
set default form values as null
  • Loading branch information
bobcaprice authored Apr 5, 2024
2 parents cfe21ee + 2b28d05 commit 1f25fbb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 40 deletions.
44 changes: 22 additions & 22 deletions ui/src/app/affiliation/affiliation-update.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,34 +132,34 @@ export class AffiliationUpdateComponent implements OnInit {

editForm = this.fb.group(
{
id: [null],
email: ['', [Validators.pattern(EMAIL_REGEXP), Validators.required]],
affiliationSection: ['', [Validators.required]],
departmentName: ['', [Validators.maxLength(4000)]],
roleTitle: ['', [Validators.maxLength(4000)]],
url: ['', [Validators.maxLength(8000)]],
id: [],
email: [null, [Validators.pattern(EMAIL_REGEXP), Validators.required]],
affiliationSection: [null, [Validators.required]],
departmentName: [null, [Validators.maxLength(4000)]],
roleTitle: [null, [Validators.maxLength(4000)]],
url: [null, [Validators.maxLength(8000)]],
startYear: [null],
startMonth: [null],
startDay: [null],
endYear: [null],
endMonth: [null],
endDay: [null],
orgName: ['', [Validators.required]],
orgCountry: ['', [Validators.required]],
orgCity: ['', [Validators.required]],
orgRegion: [''],
disambiguatedOrgId: ['', [Validators.required, disambiguatedOrgIdValidator()]],
disambiguationSource: ['', [Validators.required]],
externalId: [''],
externalIdType: [''],
externalIdUrl: [''],
putCode: [''],
created: [''],
modified: [''],
deletedFromORCID: [''],
status: [''],
ownerId: [''],
sent: [''],
orgName: [null, [Validators.required]],
orgCountry: [null, [Validators.required]],
orgCity: [null, [Validators.required]],
orgRegion: [],
disambiguatedOrgId: [null, [Validators.required, disambiguatedOrgIdValidator()]],
disambiguationSource: [null, [Validators.required]],
externalId: [],
externalIdType: [],
externalIdUrl: [],
putCode: [],
created: [],
modified: [],
deletedFromORCID: [],
status: [],
ownerId: [],
sent: [],
},
{ validators: dateValidator() }
)
Expand Down
6 changes: 3 additions & 3 deletions ui/src/app/user/user-update.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing'
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { FormBuilder, ReactiveFormsModule } from '@angular/forms'
import { ActivatedRoute, Router } from '@angular/router'
import { BehaviorSubject, Observable, of } from 'rxjs'
import { UserUpdateComponent } from './user-update.component'
import { UserService } from './service/user.service'
import { AccountService } from '../account'
Expand All @@ -11,9 +10,10 @@ import { ErrorService } from '../error/service/error.service'
import { IUser, User } from './model/user.model'
import { Member } from '../member/model/member.model'
import { UserValidation } from './model/user-validation.model'
import { RouterTestingModule } from '@angular/router/testing'
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome'
import { NO_ERRORS_SCHEMA } from '@angular/core'
import { RouterTestingModule } from '@angular/router/testing'
import { of } from 'rxjs'

describe('UserUpdateComponent', () => {
let component: UserUpdateComponent
Expand Down
35 changes: 20 additions & 15 deletions ui/src/app/user/user-update.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ChangeDetectorRef, Component, OnInit } from '@angular/core'
import { HttpResponse } from '@angular/common/http'
import { FormBuilder, Validators } from '@angular/forms'
import { FormBuilder, FormControl, Validators } from '@angular/forms'
import { ActivatedRoute, Router } from '@angular/router'
import { EMPTY, Observable } from 'rxjs'
import * as moment from 'moment'
Expand Down Expand Up @@ -32,19 +32,24 @@ export class UserUpdateComponent {
validation: any

editForm = this.fb.group({
id: [''],
email: ['', [Validators.required, Validators.email, Validators.maxLength(50), emailValidator]],
firstName: ['', Validators.required],
lastName: ['', Validators.required],
mainContact: [false],
assertionServiceEnabled: [false],
salesforceId: ['', Validators.required],
activated: [false],
isAdmin: [false],
createdBy: [''],
createdDate: [''],
lastModifiedBy: [''],
lastModifiedDate: [''],
id: new FormControl<string | null>(null),
email: new FormControl<string | null>(null, [
Validators.required,
Validators.email,
Validators.maxLength(50),
emailValidator,
]),
firstName: new FormControl<string | null>(null, Validators.required),
lastName: new FormControl<string | null>(null, Validators.required),
mainContact: new FormControl<boolean | null>(null),
assertionServiceEnabled: new FormControl<boolean | null>(null),
salesforceId: new FormControl<string | null>(null, Validators.required),
activated: new FormControl<boolean | null>(null),
isAdmin: new FormControl<boolean | null>(null),
createdBy: new FormControl<string | null>(null),
createdDate: new FormControl<string | null>(null),
lastModifiedBy: new FormControl<string | null>(null),
lastModifiedDate: new FormControl<string | null>(null),
})

memberList = [] as IMember[]
Expand Down Expand Up @@ -279,7 +284,7 @@ export class UserUpdateComponent {
private createFromForm(): IUser {
return {
...new User(),
id: this.editForm.get(['id'])?.value !== '' ? this.editForm.get(['id'])?.value : undefined,
id: this.editForm.get(['id'])?.value ? this.editForm.get(['id'])?.value : undefined,
email: this.editForm.get(['email'])?.value,
firstName: this.editForm.get(['firstName'])?.value,
lastName: this.editForm.get(['lastName'])?.value,
Expand Down

0 comments on commit 1f25fbb

Please sign in to comment.