From 84aedb32a1c6908f2e249f3529101698f9edfe5e Mon Sep 17 00:00:00 2001 From: harshitg927 Date: Sat, 22 Feb 2025 15:43:45 +0530 Subject: [PATCH 1/2] fix: Restrict first name and last name fields to alphabets only --- .../components/patient/CreatePatientForm.js | 18 +++++++++++++++++- .../components/patient/SearchPatientForm.js | 16 ++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/frontend/src/components/patient/CreatePatientForm.js b/frontend/src/components/patient/CreatePatientForm.js index d455901895..cc7a203318 100644 --- a/frontend/src/components/patient/CreatePatientForm.js +++ b/frontend/src/components/patient/CreatePatientForm.js @@ -205,6 +205,20 @@ function CreatePatientForm(props) { ); }; + function handleFirstNameChange(event) { + const regex = /^[A-Za-z]*$/; + if (!regex.test(event.target.value)) { + event.target.value = event.target.value.replace(/[^A-Za-z]/g, ""); + } + } + + function handleLastNameChange(event) { + const regex = /^[A-Za-z]*$/; + if (!regex.test(event.target.value)) { + event.target.value = event.target.value.replace(/[^A-Za-z]/g, ""); + } + } + function fetchHealthDistrictsCallback(res) { setHealthDistricts(res); } @@ -376,7 +390,7 @@ function CreatePatientForm(props) { addNotification({ title: intl.formatMessage({ id: "notification.title" }), message: intl.formatMessage({ id: "error.save.patient" }), - kind: NotificationKinds.error, + kind: NotificationKinds.error , }); } }; @@ -525,6 +539,7 @@ function CreatePatientForm(props) { placeholder={intl.formatMessage({ id: "patient.information.lastname", })} + onChange={(e) => handleLastNameChange(e)} /> )} @@ -544,6 +559,7 @@ function CreatePatientForm(props) { placeholder={intl.formatMessage({ id: "patient.information.firstname", })} + onChange={(e) => handleFirstNameChange(e)} /> )} diff --git a/frontend/src/components/patient/SearchPatientForm.js b/frontend/src/components/patient/SearchPatientForm.js index 42e8525c2d..82f7ae1aed 100644 --- a/frontend/src/components/patient/SearchPatientForm.js +++ b/frontend/src/components/patient/SearchPatientForm.js @@ -231,6 +231,20 @@ function SearchPatientForm(props) { setDob(date); }; + const handleFirstNameChange = (event) => { + const regex = /^[A-Za-z]*$/; + if (!regex.test(event.target.value)) { + event.target.value = event.target.value.replace(/[^A-Za-z]/g, ""); + } + }; + + const handleLastNameChange = (event) => { + const regex = /^[A-Za-z]*$/; + if (!regex.test(event.target.value)) { + event.target.value = event.target.value.replace(/[^A-Za-z]/g, ""); + } + }; + const patientSelected = (e) => { const patientSelected = patientSearchResults.find((patient) => { return patient.patientID == e.target.id; @@ -349,6 +363,7 @@ function SearchPatientForm(props) { defaultMessage: "Last Name", })} id={field.name} + onChange={(e) => handleLastNameChange(e)} /> )} @@ -366,6 +381,7 @@ function SearchPatientForm(props) { defaultMessage: "First Name", })} id={field.name} + onChange={(e) => handleFirstNameChange(e)} /> )} From edc95256279c6ebe7654af20d87095c000181208 Mon Sep 17 00:00:00 2001 From: harshitg927 Date: Sat, 22 Feb 2025 15:44:42 +0530 Subject: [PATCH 2/2] formatted the code using npm run format --- frontend/src/components/patient/CreatePatientForm.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/components/patient/CreatePatientForm.js b/frontend/src/components/patient/CreatePatientForm.js index cc7a203318..9d8e751438 100644 --- a/frontend/src/components/patient/CreatePatientForm.js +++ b/frontend/src/components/patient/CreatePatientForm.js @@ -390,7 +390,7 @@ function CreatePatientForm(props) { addNotification({ title: intl.formatMessage({ id: "notification.title" }), message: intl.formatMessage({ id: "error.save.patient" }), - kind: NotificationKinds.error , + kind: NotificationKinds.error, }); } };