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

negative value for age input #1375 #1379

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions frontend/src/components/patient/CreatePatientForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,14 @@ function CreatePatientForm(props) {
})}
id="years"
type="number"
onChange={(e) => handleYearsChange(e, values)}
min="0" // Prevent negative years
onChange={(e) => {
const value = Math.max(0, parseInt(e.target.value || 0)); // Ensure no negative values
handleYearsChange(
{ ...e, target: { ...e.target, value } },
values,
);
}}
placeholder={intl.formatMessage({
id: "patient.information.age",
})}
Expand All @@ -637,8 +644,17 @@ function CreatePatientForm(props) {
name="months"
labelText={intl.formatMessage({ id: "patient.age.months" })}
type="number"
onChange={(e) => handleMonthsChange(e, values)}
id="months"
min="0" // Prevent negative months
max="11" // Limit months to 0–11
onChange={(e) => {
let value = parseInt(e.target.value || 0);
value = Math.min(11, Math.max(0, value)); // value between 0 and 11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This Logic is already handles

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which line, can you please explain a bit?

handleMonthsChange(
{ ...e, target: { ...e.target, value } },
values,
);
}}
placeholder={intl.formatMessage({
id: "patient.information.months",
})}
Expand All @@ -649,16 +665,22 @@ function CreatePatientForm(props) {
value={dateOfBirthFormatter.days}
name="days"
type="number"
onChange={(e) => handleDaysChange(e, values)}
labelText={intl.formatMessage({ id: "patient.age.days" })}
id="days"
min="0" // Prevent negative days
max="30" // Limit days to 0–30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you cant hard code 30 as the max days as this varies depensidn on the month

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay will change it to 31 or can make changes to code on month conditions also

onChange={(e) => {
let value = parseInt(e.target.value || 0);
value = Math.min(30, Math.max(0, value)); //value between 0 and 30
handleDaysChange(
{ ...e, target: { ...e.target, value } },
values,
);
}}
labelText={intl.formatMessage({ id: "patient.age.days" })}
placeholder={intl.formatMessage({
id: "patient.information.days",
})}
/>
<div className="error">
<ErrorMessage name="birthDateForDisplay"></ErrorMessage>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you remove this error message intentionally ??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nopes should i fix it?

</div>
</Column>
<Column lg={16} md={8} sm={4}>
{" "}
Expand Down
Loading