Skip to content

Commit

Permalink
(feat) Manually Trigger Form Validation (#808)
Browse files Browse the repository at this point in the history
Manually trigger just the validation
  • Loading branch information
ZacButko committed Sep 15, 2022
1 parent 5f1b158 commit d3d9547
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ export class FeWrapperComponent implements OnInit, OnDestroy {
this.changeState('readyWithValidationErrors');
}

this.onValidate(this.form.valid);

return this.form.valid;
}

Expand Down Expand Up @@ -252,14 +254,23 @@ export class FeWrapperComponent implements OnInit, OnDestroy {
if (handlePostResponse && typeof handlePostResponse === 'function') handlePostResponse(encounter);
}

public onValidate(valid: boolean): void {
const handleOnValidate = this.singleSpaPropsService.getProp('handleOnValidate');
if (handleOnValidate && typeof handleOnValidate === 'function') handleOnValidate(valid);
}

@HostListener('window:ampath-form-action', ['$event'])
onFormAction(event) {
const formUuid = this.singleSpaPropsService.getPropOrThrow('formUuid');
if (event.detail?.formUuid === formUuid) {
const patientUuid = this.singleSpaPropsService.getPropOrThrow('patientUuid');
if (event.detail?.formUuid === formUuid && event.detail?.patientUuid === patientUuid) {
switch (event.detail?.action) {
case 'onSubmit':
this.onSubmit();
break;
case 'validateForm':
this.validateForm();
break;
default:
break;
}
Expand Down
1 change: 1 addition & 0 deletions packages/esm-form-entry-app/src/single-spa-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ export type SingleSpaProps = AppProps & {
patientUuid: string;
handleEncounterCreate?: (encounter: EncounterCreate) => void;
handlePostResponse?: (encounter: Encounter) => void;
handleOnValidate?: (valid: boolean) => void;
showDiscardSubmitButtons?: boolean;
};

0 comments on commit d3d9547

Please sign in to comment.