From e14f4c44138fcdb8f252b5b2a4f904899b0f9303 Mon Sep 17 00:00:00 2001 From: Ojwang' Antony Date: Wed, 17 Jan 2024 14:43:27 +0300 Subject: [PATCH] mark fields in the lab result form as required (#37) * mark fields in the lab result form as required * mend --- src/results/result-form-field.component.tsx | 20 ++++++++++++++++- src/results/result-form.component.tsx | 24 +++++++++++---------- src/results/result-form.scss | 4 ++++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/src/results/result-form-field.component.tsx b/src/results/result-form-field.component.tsx index cc768c9..f74aa6f 100644 --- a/src/results/result-form-field.component.tsx +++ b/src/results/result-form-field.component.tsx @@ -9,11 +9,12 @@ interface ResultFormFieldProps { concept: ConceptReference; control: any; register: any; + errors: any; } const ResultFormField: React.FC = ({ concept, control, - register, + errors, }) => { const { t } = useTranslation(); const isTextOrNumeric = (concept) => @@ -24,9 +25,15 @@ const ResultFormField: React.FC = ({ return ( <> + {Object.keys(errors).length > 0 && ( +
All fields are required
+ )} {isTextOrNumeric(concept) && ( ( = ({ )} /> )} + {isCoded(concept) && ( ( = ({ order, patientUuid }) => { const { control, register, - formState: { isSubmitting }, + formState: { isSubmitting, errors }, getValues, + handleSubmit, } = useForm<{ testResult: string }>({ defaultValues: {}, }); @@ -52,7 +53,7 @@ const ResultForm: React.FC = ({ order, patientUuid }) => { return
Loading test details
; } - const handleSubmit = (e) => { + const onSubmit = (data, e) => { e.preventDefault(); // assign result to test order const documentedValues = getValues(); @@ -168,16 +169,17 @@ const ResultForm: React.FC = ({ order, patientUuid }) => { )} {/* // we need to display test name for test panels */} - {concept.setMembers.length > 0 && ( -
Test panel: {concept.display}
- )} + {concept.setMembers.length > 0 &&
{concept.display}
} {concept && (
- +
+ +
)} @@ -190,7 +192,7 @@ const ResultForm: React.FC = ({ order, patientUuid }) => { > {t("cancel", "Cancel")} - + diff --git a/src/results/result-form.scss b/src/results/result-form.scss index 12aca1b..03d1f27 100644 --- a/src/results/result-form.scss +++ b/src/results/result-form.scss @@ -16,4 +16,8 @@ section { .textInput { margin: 5px; +} + +.errorDiv { + color: red; } \ No newline at end of file