Skip to content

Commit

Permalink
feat: conditionally required check
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit committed Oct 1, 2024
1 parent a26f64b commit b08c335
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,26 @@ export class ContractAgreementTransferDialogForm {
showAllHttpParameterizationFields: [false],

httpProxiedPath: [''],
httpProxiedMethod: ['', Validators.required],
httpProxiedMethod: [''],
httpProxiedQueryParams: this.formBuilder.array(
new Array<FormGroup<HttpDatasourceQueryParamFormModel>>(),
),
httpProxiedBody: [''],
httpProxiedBodyContentType: [''],
});

all
.get('showAllHttpParameterizationFields')!
.valueChanges.subscribe((value) => {
console.log('showAllHttpParameterizationFields', value);
if (value) {
all.get('httpProxiedMethod')!.setValidators([Validators.required]);
} else {
all.get('httpProxiedMethod')!.clearValidators();
}
all.get('httpProxiedMethod')!.updateValueAndValidity();
});

switchDisabledControls<ContractAgreementTransferDialogFormValue>(
all,
(value) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,11 @@ <h1 mat-dialog-title>
{{ 'contract_agreement_page.http_fields' | translate }}
</button>
</div>
show all methods:
{{ form.all.controls.showAllHttpParameterizationFields.value }}
proxy method:
{{ isRequiredField('httpProxiedMethod') }}
<br />
</ng-container>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Component, Inject, OnDestroy} from '@angular/core';
import {AbstractControl} from '@angular/forms';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {Observable, Subject} from 'rxjs';
import {finalize} from 'rxjs/operators';
Expand Down Expand Up @@ -164,4 +165,14 @@ export class ContractAgreementTransferDialogComponent implements OnDestroy {
transferProcessRequestJsonLd: value.transferProcessRequest!,
};
}

isRequiredField(field: string) {
const form_field = this.form.all.get(field);
if (!form_field || !form_field.validator) {
return false;
}

const validator = form_field.validator({} as AbstractControl);
return validator && validator.required;
}
}

0 comments on commit b08c335

Please sign in to comment.