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

Issue 1594 - Enhance Phone Number Input Handling with State Management and Validation #1720

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

blitzboah
Copy link

@blitzboah blitzboah commented Mar 19, 2025

Pull Requests Requirements

  • The PR title includes a brief description of the work done, including the
    Issue number if applicable.
  • The PR includes a video showing the changes for the work done.
  • The PR title follows conventional commit label standards.
  • The changes confirm to the OpenElis Global x3 Styleguide and design
    documentation.
  • The changes include tests or are validated by existing tests.
  • I have read and agree to the Contributing Guidelines of this project.

Summary

This PR improves the phone number input handling by:

  • Using React state to manage the phone number value.
  • Allowing only valid characters (+, numbers, and -).

Related Issue

#1594

@@ -614,7 +644,7 @@ function CreatePatientForm(props) {
<Field name="primaryPhone">
{({ field }) => (
<TextInput
value={values.primaryPhone || ""}
value={phoneNumber}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This doesnt set a phone values for an existing patient

const phoneRegex = new RegExp(escapedPhoneFormat);

if (!phoneRegex.test(value)) {
console.warn("Invalid phone number format");
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should be a visible message on the UI not just in the console

Copy link
Author

Choose a reason for hiding this comment

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

does alert works?


setPhoneNumber(value);

if (configurationProperties.PHONE_FORMAT && value.length > 10) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

why would you hard code a specific lenght

Copy link
Author

Choose a reason for hiding this comment

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

the length check was initially added to prevent premature validation while the user was still typing

Copy link
Collaborator

@mozzy11 mozzy11 Mar 19, 2025

Choose a reason for hiding this comment

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

On the old UI , there was an ajax call to validate the phone numbers. see where its used

Copy link
Author

Choose a reason for hiding this comment

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

I checked the old UI and found the Ajax call for phone number validation, but I couldn't get it to work in the latest version. It seems like the Ajax validation might not be in use anymore. For now, I have ensured that only numeric input is allowed in the phone field. Let me know if there's a specific API or validation method I should use instead!

Copy link
Author

Choose a reason for hiding this comment

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

@mozzy11 I noticed that the phone number validation API returns true only when the phone number is encoded (e.g., %2B225-12-23-56-23) but returns false for the same number when sent as +225-12-23-56-23 or without + as well

here's the controller CommonValidationsRestController.java.
.

image
image

For handling this on the frontend, should I:

  1. Call the API on form submission and show a notification if the phone number is invalid?
  2. Validate using regex on the frontend only and display an error message directly below the phone number field?

@blitzboah
Copy link
Author

@mozzy11, I've implemented changes so that on form submission, the API will validate the phone number. The backend service expects the + to be URL-encoded and the number to follow the format 225-xx-xx-xx-xx, as mentioned in my previous response.

Here are some screenshots for reference:

image
image

let me know if you're good with these changes, or I can roll back to the previous implementation, which only accepted numeric input.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants