seas-computing / seas-computing/mark-one
Form field validation handler prop
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 0
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
It would be useful for form fields to have an (optional) validator prop. This prop expects a Validator function to determine if the field is valid or not. This Validator function will be passed the value of the field onChange and return an array of strings representing the validation errors.
An example might look like this:
<TextInput
id={'user-name'}
name={'user-name'}
label={'Name'}
value={username}
onChange={(e}: ChangeEvent<HTMLInputElement>) => { /* Do something with the value */ }
validator={(value: string) => {
return value.includes(/elmo/) ? ['Elmo may not use this app'] : []
}}
/>

Returning an array of multiple strings would cause them all to be displayed one after the other
<TextInput
id={'user-name'}
name={'user-name'}
label={'Name'}
value={username}
onChange={(e}: ChangeEvent<HTMLInputElement>) => { /* Do something with the value */ }
validator={(value: string) => {
return ['Elmo', 'Kermit'].includes(value) ? ['Elmo may not use this app', 'Kermit may not use this app'] : []
}}
/>

This would outsource (for want of a better term) the management of isValid/isNotValid type state to the form inputs themselves.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the TextInput and other form-field component entry points, then inspect how isValid/isNotValid state is currently managed. The issue provides no file or test names. Done means an optional validator accepts the field value, returns validation-error strings, and displays multiple returned errors in the field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100