Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled auto-switch feature for DOB input on the Patient Registration page #9870

Merged
merged 14 commits into from
Jan 15, 2025
Merged
34 changes: 28 additions & 6 deletions src/components/Patient/PatientRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,12 +503,22 @@ export default function PatientRegistration(
value={
form.watch("date_of_birth")?.split("-")[2]
}
onChange={(e) =>
onChange={(e) => {
form.setValue(
"date_of_birth",
`${form.watch("date_of_birth")?.split("-")[0]}-${form.watch("date_of_birth")?.split("-")[1]}-${e.target.value}`,
)
}
);
const day = parseInt(e.target.value);
if (
e.target.value.length === 2 &&
day >= 1 &&
day <= 31
) {
document
.getElementById("dob-month-input")
?.focus();
}
}}
data-cy="dob-day-input"
/>
</div>
Expand All @@ -518,17 +528,28 @@ export default function PatientRegistration(

<Input
type="number"
id="dob-month-input"
placeholder="MM"
{...field}
value={
form.watch("date_of_birth")?.split("-")[1]
}
onChange={(e) =>
onChange={(e) => {
form.setValue(
"date_of_birth",
`${form.watch("date_of_birth")?.split("-")[0]}-${e.target.value}-${form.watch("date_of_birth")?.split("-")[2]}`,
)
}
);
const month = parseInt(e.target.value);
if (
e.target.value.length === 2 &&
month >= 1 &&
month <= 12
) {
document
.getElementById("dob-year-input")
?.focus();
}
}}
data-cy="dob-month-input"
/>
</div>
Expand All @@ -538,6 +559,7 @@ export default function PatientRegistration(

<Input
type="number"
id="dob-year-input"
placeholder="YYYY"
{...field}
value={
Expand Down
Loading