bitovi / bitovi/react-numerics

validation

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
accepted enhancement
Dominant language
TypeScript
Stars
0
Forks
1
PR merge metrics
No merged PRs in 30d

Description

Currently the fields don't support validation. Given that validation is needed when a field value changes I believe:

1. There is no need to validate as the user types since the `filter` and `formatter` functions **do not allow** the user to enter bad data.
1. When the the field initializes and an initial numeric value is provided if the value doesn't pass through the `filter` and `formatter` the filed will emit a numeric changed event with a blank string. I'm not entirely sure what a better course of action is here, allowing the value to be displayed may result in issues later on when the user tries to type; for example in the case of an SSN where the initial numeric value is too long typing would result in truncating the number? Blank the field and flag it as invalid?
1. Finally when an entire form that the field is part of is validated the user must enter a valid number for required fields. Fields like currency and percent will create a valid number on blur, an SSN could be partially filled in, any field could be blank. Those differences probably matter and might need to be handled differently.

My hope is that validation could be handled similarly to `filter` and `formatter`. A prop on NumericInput that accepts a single function that implement the `Validate` interface which can be invoked when a standard DOM `form` validation request happens. Creating the validate function might require (probably requires) a factory function that returns a `Validate` function.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating NumericInput and the existing filter and formatter APIs. Trace how initial numeric values, blur behavior, and standard DOM form validation are handled, then define the Validate interface and factory behavior for required, blank, partial, currency, percent, and SSN cases. Done means the validation contract and resulting field behavior are agreed and covered for those cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.