From bc7ef6b0f7880ae237eece16abcb112599702910 Mon Sep 17 00:00:00 2001 From: mohanrajnambe Date: Fri, 8 Mar 2024 12:00:31 +0530 Subject: [PATCH 1/3] Handle no option available case when result array is empty --- src/Components/Patient/PatientRegister.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Components/Patient/PatientRegister.tsx b/src/Components/Patient/PatientRegister.tsx index efc269fa00c..c7e64b87dea 100644 --- a/src/Components/Patient/PatientRegister.tsx +++ b/src/Components/Patient/PatientRegister.tsx @@ -1464,10 +1464,15 @@ export const PatientRegister = (props: PatientRegisterProps) => { required placeholder={ field("district").value - ? "Choose Localbody" + ? !localBody.length + ? "No options available" + : "Choose Localbody" : "Select District First" } - disabled={!field("district").value} + disabled={ + !field("district").value || + !localBody.length + } options={localBody} optionLabel={(o: any) => o.name} optionValue={(o: any) => o.id} From b4304b3f83cb6f3c02d7179174f9f56af84f60db Mon Sep 17 00:00:00 2001 From: mohanrajnambe Date: Thu, 14 Mar 2024 22:52:00 +0530 Subject: [PATCH 2/3] Add Length check validation in rendering Select List --- src/Components/Form/SelectMenuV2.tsx | 72 +++++++++++++++------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/src/Components/Form/SelectMenuV2.tsx b/src/Components/Form/SelectMenuV2.tsx index 2e277b40b4f..718b4e796b2 100644 --- a/src/Components/Form/SelectMenuV2.tsx +++ b/src/Components/Form/SelectMenuV2.tsx @@ -116,40 +116,46 @@ const SelectMenuV2 = (props: SelectMenuProps) => { props.position === "above" ? "bottom-0 mb-12" : "top-0 mt-12" )} > - - - {options.map((option, index) => ( - - {({ active, selected }) => ( -
-
- {option.label} - {props.optionIcon - ? option.icon - : selected && ( - - )} + {options.length ? ( + + + {options.map((option, index) => ( + + {({ active, selected }) => ( +
+
+ {option.label} + {props.optionIcon + ? option.icon + : selected && ( + + )} +
+ {option.description && ( +

+ {option.description} +

+ )}
- {option.description && ( -

- {option.description} -

- )} -
- )} - - ))} - - + )} + + ))} + + + ) : ( + <> + )}
From 80a9ef108dcf1cd09555c3393d436cbc47e9b811 Mon Sep 17 00:00:00 2001 From: mohanrajnambe Date: Sat, 30 Mar 2024 23:28:57 +0530 Subject: [PATCH 3/3] Add validation in the Select Component --- src/Components/Form/SelectMenuV2.tsx | 5 +++-- src/Components/Patient/PatientRegister.tsx | 9 ++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Components/Form/SelectMenuV2.tsx b/src/Components/Form/SelectMenuV2.tsx index 640f3163b9d..2c22510cef1 100644 --- a/src/Components/Form/SelectMenuV2.tsx +++ b/src/Components/Form/SelectMenuV2.tsx @@ -59,7 +59,8 @@ const SelectMenuV2 = (props: SelectMenuProps) => { const showChevronIcon = props.showChevronIcon ?? true; - const placeholder = props.placeholder ?? "Select"; + const placeholder = + valueOptions?.length > 0 ? props.placeholder ?? "Select" : "No options"; const defaultOption = { label: placeholder, selectedLabel:

{placeholder}

, @@ -77,7 +78,7 @@ const SelectMenuV2 = (props: SelectMenuProps) => { return (
props.onChange(selection.value)} > diff --git a/src/Components/Patient/PatientRegister.tsx b/src/Components/Patient/PatientRegister.tsx index 00cd88bf6ac..85a5002f8da 100644 --- a/src/Components/Patient/PatientRegister.tsx +++ b/src/Components/Patient/PatientRegister.tsx @@ -1487,15 +1487,10 @@ export const PatientRegister = (props: PatientRegisterProps) => { required placeholder={ field("district").value - ? !localBody.length - ? "No options available" - : "Choose Localbody" + ? "Choose Localbody" : "Select District First" } - disabled={ - !field("district").value || - !localBody.length - } + disabled={!field("district").value} options={localBody} optionLabel={(o: any) => o.name} optionValue={(o: any) => o.id}