From 80a9ef108dcf1cd09555c3393d436cbc47e9b811 Mon Sep 17 00:00:00 2001 From: mohanrajnambe Date: Sat, 30 Mar 2024 23:28:57 +0530 Subject: [PATCH] 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}