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

7058-input-validation #988

Merged
merged 6 commits into from
Dec 9, 2024
Merged

7058-input-validation #988

merged 6 commits into from
Dec 9, 2024

Conversation

ttoomey
Copy link
Contributor

@ttoomey ttoomey commented Dec 5, 2024

prevent non-numeric values

Description

GH Issue

Related warehouse issue for backend validation

Restrict numeric inputs to numeric characters. Adds react-number-format to avoid the complexities of scrubbing user input. Also supports commas

Type of change

  • Bug fix
  • New feature (adds functionality)
  • New dependency

Testing

should exercise the multitude of keyboard entries:

  • integers (non-zero leading)
  • decimals (non-zero leading)
  • just 0
  • 0.0x
  • negative numbers
  • copy & paste
  • undo

See testing instructions in the wh PR

Checklist before requesting review

  • I have performed a self-review of my code
  • I have run the code that is being changed under ideal conditions, and it doesn't fail
  • My code includes comments and/or descriptive variable names to help other engineers understand the intent (or not applicable)
  • My code follows the style guidelines of this project (eslint)
  • I have updated the documentation (or not applicable)
  • If it's not obvious how to test this change, I have provided testing instructions in this PR or the related issue

@ttoomey ttoomey requested a review from gigxz December 5, 2024 04:38
@ttoomey ttoomey marked this pull request as ready for review December 5, 2024 04:38
const [errorMessage, setErrorMessage] = useState<string | null>(null);

const currencyInputProps = currency
Copy link
Contributor Author

Choose a reason for hiding this comment

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

replaced with MUI's InputAdornment

@ttoomey
Copy link
Contributor Author

ttoomey commented Dec 5, 2024

@gigxz per our discussion I've replaced the custom key handler with react-number-format

Copy link
Collaborator

@gigxz gigxz left a comment

Choose a reason for hiding this comment

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

excellent, thanks!!

) : undefined,
...InputProps,
}}
{...(props as any)}
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems like NumericFormat actually does handle the typing correctly s-yadav/react-number-format#577
but we run into issues where TextInputProps differ from NumericFormat props. The below keeps typescript happy without the cast:

      defaultValue={(defaultValue || '') as string}
      type={type as any}
      {...props}

(pulling out defaultValue and type from the props object)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I pushed it since I had it locally anyway: f0721bb lmk what you think!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a nice improvement, thanks!

@gigxz gigxz changed the base branch from release-142 to release-143 December 9, 2024 20:07
@ttoomey ttoomey merged commit caafe54 into release-143 Dec 9, 2024
3 checks passed
@ttoomey ttoomey deleted the 7058-input-validation branch December 9, 2024 23:55
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