diff --git a/frontend/cypress/pages/ModifyOrderPage.js b/frontend/cypress/pages/ModifyOrderPage.js index efddfb1e1..759586679 100644 --- a/frontend/cypress/pages/ModifyOrderPage.js +++ b/frontend/cypress/pages/ModifyOrderPage.js @@ -41,9 +41,9 @@ class ModifyOrderPage { clickRespectivePatient() { return cy - .get('tbody tr') - .first() - .find('.cds--radio-button__appearance') + .get("tbody tr") + .first() + .find(".cds--radio-button__appearance") .click(); } } diff --git a/frontend/src/components/patient/CreatePatientForm.js b/frontend/src/components/patient/CreatePatientForm.js index 1f16d7efe..f9de1bd7c 100644 --- a/frontend/src/components/patient/CreatePatientForm.js +++ b/frontend/src/components/patient/CreatePatientForm.js @@ -143,8 +143,16 @@ function CreatePatientForm(props) { }; function handleYearsChange(e, values) { - setPatientDetails(values); - let years = e.target.value; + // Ensure years is not negative + const years = Math.max(0, Number(e.target.value)); + + // Update form values with the validated years + setPatientDetails({ + ...values, + // Update the specific field that contains years to ensure the form shows the corrected value + [e.target.name]: years, + }); + let dobFormatter = { ...dateOfBirthFormatter, years: years, @@ -153,8 +161,16 @@ function CreatePatientForm(props) { } function handleMonthsChange(e, values) { - setPatientDetails(values); - let months = e.target.value; + // Ensure months is not negative + const months = Math.max(0, Number(e.target.value)); + + // Update form values with the validated months + setPatientDetails({ + ...values, + // Update the specific field that contains months to ensure the form shows the corrected value + [e.target.name]: months, + }); + let dobFormatter = { ...dateOfBirthFormatter, months: months, @@ -163,8 +179,16 @@ function CreatePatientForm(props) { } function handleDaysChange(e, values) { - setPatientDetails(values); - let days = e.target.value; + // Ensure days is not negative + const days = Math.max(0, Number(e.target.value)); + + // Update form values with the validated days + setPatientDetails({ + ...values, + // Update the specific field that contains days to ensure the form shows the corrected value + [e.target.name]: days, + }); + let dobFormatter = { ...dateOfBirthFormatter, days: days, @@ -625,6 +649,7 @@ function CreatePatientForm(props) { })} id="years" type="number" + min="0" onChange={(e) => handleYearsChange(e, values)} placeholder={intl.formatMessage({ id: "patient.information.age", @@ -637,6 +662,7 @@ function CreatePatientForm(props) { name="months" labelText={intl.formatMessage({ id: "patient.age.months" })} type="number" + min="0" onChange={(e) => handleMonthsChange(e, values)} id="months" placeholder={intl.formatMessage({ @@ -649,6 +675,7 @@ function CreatePatientForm(props) { value={dateOfBirthFormatter.days} name="days" type="number" + min="0" onChange={(e) => handleDaysChange(e, values)} labelText={intl.formatMessage({ id: "patient.age.days" })} id="days"