Skip to content

Commit

Permalink
Merge pull request #1159 from ORCID/fix-empty-form-fields
Browse files Browse the repository at this point in the history
fix empty values again
  • Loading branch information
bobcaprice authored Apr 12, 2024
2 parents a9d8f62 + 33a73ac commit d08dd4c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 49 deletions.
58 changes: 29 additions & 29 deletions ui/src/app/affiliation/affiliation-update.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function dateValidator() {

function disambiguatedOrgIdValidator(): ValidatorFn {
return (control: AbstractControl): { [key: string]: boolean } | null => {
if (control.parent !== undefined) {
if (control.parent) {
const disambiguationSourceValue = control.parent?.get('disambiguationSource')?.value
if (disambiguationSourceValue === 'RINGGOLD') {
const reg = new RegExp('^\\d+$')
Expand Down Expand Up @@ -200,14 +200,14 @@ export class AffiliationUpdateComponent implements OnInit {
onChanges(): void {
this.editForm.get('startMonth')?.valueChanges.subscribe((val) => {
this.startDaysList = this.dateUtilService.getDaysList(
this.editForm.get('startYear')?.value || undefined,
this.editForm.get('startMonth')?.value || undefined
this.editForm.get('startYear')?.value || null,
this.editForm.get('startMonth')?.value || null
)
})
this.editForm.get('endMonth')?.valueChanges.subscribe((val) => {
this.endDaysList = this.dateUtilService.getDaysList(
this.editForm.get('endYear')?.value || undefined,
this.editForm.get('endMonth')?.value || undefined
this.editForm.get('endYear')?.value || null,
this.editForm.get('endMonth')?.value || null
)
})
this.editForm.get('disambiguationSource')?.valueChanges.subscribe((value) => {
Expand All @@ -219,24 +219,24 @@ export class AffiliationUpdateComponent implements OnInit {
updateForm(assertion: IAffiliation) {
if (assertion?.id) {
this.editForm.patchValue({
id: assertion.id || null,
id: assertion.id,
email: assertion.email?.trim(),
affiliationSection: assertion.affiliationSection,
departmentName: assertion.departmentName || null,
roleTitle: assertion.roleTitle || null,
url: assertion.url || null,
startYear: assertion.startYear || null,
departmentName: assertion.departmentName,
roleTitle: assertion.roleTitle,
url: assertion.url,
startYear: assertion.startYear,
startMonth: parseInt(assertion.startMonth || '') || null,
startDay: assertion.startDay || null,
endYear: assertion.endYear || null,
startDay: assertion.startDay,
endYear: assertion.endYear,
endMonth: parseInt(assertion.endMonth || '') || null,
endDay: assertion.endDay || null,
orgName: assertion.orgName || null,
orgCountry: assertion.orgCountry || null,
orgCity: assertion.orgCity || null,
orgRegion: assertion.orgRegion || null,
disambiguatedOrgId: assertion.disambiguatedOrgId || null,
disambiguationSource: assertion.disambiguationSource || null,
endDay: assertion.endDay,
orgName: assertion.orgName,
orgCountry: assertion.orgCountry,
orgCity: assertion.orgCity,
orgRegion: assertion.orgRegion,
disambiguatedOrgId: assertion.disambiguatedOrgId,
disambiguationSource: assertion.disambiguationSource,
externalId: assertion.externalId,
externalIdType: assertion.externalIdType,
externalIdUrl: assertion.externalIdUrl,
Expand Down Expand Up @@ -283,27 +283,27 @@ export class AffiliationUpdateComponent implements OnInit {
private createFromForm(): IAffiliation {
return {
...new Affiliation(),
id: this.editForm.get(['id'])?.value,
email: this.editForm.get(['email'])?.value,
id: this.editForm.get(['id'])?.value || null,
email: this.editForm.get(['email'])?.value || null,
affiliationSection: this.editForm.get(['affiliationSection'])?.value,
departmentName: this.editForm.get(['departmentName'])?.value,
roleTitle: this.editForm.get(['roleTitle'])?.value,
url: this.editForm.get(['url'])?.value,
departmentName: this.editForm.get(['departmentName'])?.value || null,
roleTitle: this.editForm.get(['roleTitle'])?.value || null,
url: this.editForm.get(['url'])?.value || null,
startYear: this.editForm.get(['startYear'])?.value,
startMonth: this.editForm.get(['startMonth'])?.value,
startDay: this.editForm.get(['startDay'])?.value,
endYear: this.editForm.get(['endYear'])?.value,
endMonth: this.editForm.get(['endMonth'])?.value,
endDay: this.editForm.get(['endDay'])?.value,
orgName: this.editForm.get(['orgName'])?.value,
orgName: this.editForm.get(['orgName'])?.value || null,
orgCountry: this.editForm.get(['orgCountry'])?.value,
orgCity: this.editForm.get(['orgCity'])?.value,
orgRegion: this.editForm.get(['orgRegion'])?.value,
orgRegion: this.editForm.get(['orgRegion'])?.value || null,
disambiguatedOrgId: this.editForm.get(['disambiguatedOrgId'])?.value,
disambiguationSource: this.editForm.get(['disambiguationSource'])?.value,
externalId: this.editForm.get(['externalId'])?.value,
externalIdType: this.editForm.get(['externalIdType'])?.value,
externalIdUrl: this.editForm.get(['externalIdUrl'])?.value,
externalId: this.editForm.get(['externalId'])?.value || null,
externalIdType: this.editForm.get(['externalIdType'])?.value || null,
externalIdUrl: this.editForm.get(['externalIdUrl'])?.value || null,
putCode: this.editForm.get(['putCode'])?.value,
created:
this.editForm.get(['created'])?.value != null
Expand Down
40 changes: 20 additions & 20 deletions ui/src/app/member/member-update.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { faBan, faSave } from '@fortawesome/free-solid-svg-icons'

function parentSalesforceIdValidator(): ValidatorFn {
return (control: AbstractControl): { [key: string]: boolean } | null => {
if (control.parent !== undefined && control.value !== undefined && isNaN(control.value)) {
if (control.parent && control.value && isNaN(control.value)) {
const parentSalesforceId = control.value
const isConsortiumLead = control.parent?.get('isConsortiumLead')?.value
const salesforceId = control.parent?.get('salesforceId')?.value
Expand All @@ -26,7 +26,7 @@ function parentSalesforceIdValidator(): ValidatorFn {

function clientIdValidator(): ValidatorFn {
return (control: AbstractControl): { [key: string]: boolean } | null => {
if (control.parent !== undefined && control.value !== undefined && isNaN(control.value)) {
if (control.parent && control.value && isNaN(control.value)) {
const clientIdValue = control.value
const isConsortiumLead = control.parent?.get('isConsortiumLead')?.value
const assertionServiceEnabled = control.parent?.get('assertionServiceEnabled')?.value
Expand All @@ -49,12 +49,12 @@ function clientIdValidator(): ValidatorFn {
}
return { validClientId: false }
}
if (control.parent !== undefined) {
if (control.parent) {
if (control.parent?.get('isConsortiumLead')?.value) {
return null
}
}
if (control.parent !== undefined) {
if (control.parent) {
if (!control.parent?.get('assertionServiceEnabled')?.value) {
return null
}
Expand Down Expand Up @@ -132,13 +132,13 @@ export class MemberUpdateComponent implements OnInit {

updateForm(member: IMember) {
this.editForm.patchValue({
id: member.id || null,
clientId: member.clientId || null,
clientName: member.clientName || null,
salesforceId: member.salesforceId || null,
parentSalesforceId: member.parentSalesforceId || null,
isConsortiumLead: member.isConsortiumLead || false,
assertionServiceEnabled: member.assertionServiceEnabled || false,
id: member.id,
clientId: member.clientId,
clientName: member.clientName,
salesforceId: member.salesforceId,
parentSalesforceId: member.parentSalesforceId,
isConsortiumLead: member.isConsortiumLead,
assertionServiceEnabled: member.assertionServiceEnabled ? true : false,
createdBy: member.createdBy,
createdDate: member.createdDate != null ? member.createdDate.format(DATE_TIME_FORMAT) : null,
lastModifiedBy: member.lastModifiedBy,
Expand All @@ -162,7 +162,7 @@ export class MemberUpdateComponent implements OnInit {
const member = this.createFromForm()
this.memberService.validate(member).subscribe((data) => {
if (data.valid) {
if (member.id !== undefined) {
if (member.id !== null) {
this.subscribeToUpdateResponse(this.memberService.update(member))
} else {
this.subscribeToSaveResponse(this.memberService.create(member))
Expand All @@ -177,23 +177,23 @@ export class MemberUpdateComponent implements OnInit {
private createFromForm(): IMember {
return {
...new Member(),
id: this.editForm.get(['id'])?.value || undefined,
clientId: this.editForm.get(['clientId'])?.value,
clientName: this.editForm.get(['clientName'])?.value,
salesforceId: this.editForm.get(['salesforceId'])?.value,
parentSalesforceId: this.editForm.get(['parentSalesforceId'])?.value,
isConsortiumLead: this.editForm.get(['isConsortiumLead'])?.value,
id: this.editForm.get(['id'])?.value || null,
clientId: this.editForm.get(['clientId'])?.value || null,
clientName: this.editForm.get(['clientName'])?.value || null,
salesforceId: this.editForm.get(['salesforceId'])?.value || null,
parentSalesforceId: this.editForm.get(['parentSalesforceId'])?.value || null,
isConsortiumLead: this.editForm.get(['isConsortiumLead'])?.value || false,
assertionServiceEnabled: this.editForm.get(['assertionServiceEnabled'])?.value ? true : false,
createdBy: this.editForm.get(['createdBy'])?.value,
createdDate:
this.editForm.get(['createdDate'])?.value != null
? moment(this.editForm.get(['createdDate'])?.value, DATE_TIME_FORMAT)
: undefined,
: null,
lastModifiedBy: this.editForm.get(['lastModifiedBy'])?.value,
lastModifiedDate:
this.editForm.get(['lastModifiedDate'])?.value != null
? moment(this.editForm.get(['lastModifiedDate'])?.value, DATE_TIME_FORMAT)
: undefined,
: null,
}
}

Expand Down

0 comments on commit d08dd4c

Please sign in to comment.