Skip to content

Commit

Permalink
disable buttons if all fields are blank
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranshu1902 committed Dec 6, 2023
1 parent 9fea2d8 commit eb79485
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion src/Components/Patient/DailyRounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const DailyRounds = (props: any) => {
const [prevReviewInterval, setPreviousReviewInterval] = useState(-1);
const [prevAction, setPreviousAction] = useState("NO_ACTION");
const [hasPreviousLog, setHasPreviousLog] = useState(false);
// const [disabled, setDisabled] = useState(true);
const headerText = !id ? "Add Consultation Update" : "Info";
const buttonText = !id ? "Save" : "Continue";

Expand Down Expand Up @@ -366,6 +367,21 @@ export const DailyRounds = (props: any) => {
});
};

const formFields = [
"physical_examination_info",
"other_details",
"symptoms",
"action",
"review_interval",
"bp",
"pulse",
"temperature",
"resp",
"ventilator_spo2",
"rhythm",
"rhythm_detail",
];

const field = (name: string) => {
return {
id: name,
Expand Down Expand Up @@ -627,7 +643,27 @@ export const DailyRounds = (props: any) => {

<div className="mt-4 flex flex-col-reverse justify-end gap-2 md:flex-row">
<Cancel onClick={() => goBack()} />
<Submit onClick={(e) => handleSubmit(e)} label={buttonText} />
<Submit
disabled={
formFields.every((field: string, index: number) => {
console.log(
index.toString() + " " + field + " " + state.form[field]
);
return (
state.form[field]?.length === 0 ||
state.form[field] === null ||
state.form[field] === undefined ||
state.form[field] === "" ||
typeof state.form[field] === undefined ||
isNaN(state.form[field])
);
}) &&
state.form.rounds_type === "NORMAL" &&
!state.form.clone_last
}
onClick={(e) => handleSubmit(e)}
label={buttonText}
/>
</div>
</form>
</Page>
Expand Down

0 comments on commit eb79485

Please sign in to comment.