Skip to content

Commit

Permalink
Add validation in the Select Component
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanrajnambe committed Mar 30, 2024
1 parent 641f70a commit 80a9ef1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/Components/Form/SelectMenuV2.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ const SelectMenuV2 = <T, V>(props: SelectMenuProps<T, V>) => {

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: <p className="font-normal text-gray-600">{placeholder}</p>,
Expand All @@ -77,7 +78,7 @@ const SelectMenuV2 = <T, V>(props: SelectMenuProps<T, V>) => {
return (
<div className={props.className} id={props.id}>
<Listbox
disabled={props.disabled}
disabled={props.disabled || valueOptions?.length === 0}
value={value}
onChange={(selection: any) => props.onChange(selection.value)}
>
Expand Down
9 changes: 2 additions & 7 deletions src/Components/Patient/PatientRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 80a9ef1

Please sign in to comment.