question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add a way to perform validation at the Field level

See original GitHub issue

Hey ! First, thanks for the awesome work, I just discovered this project and it looks great.

TL;DR: It would be great to have validation at the Field level and not only at the Form level

There’s a feature that I think is missing, or I didn’t find any way to accomplish what I’d like to do: basically, I’d like to write custom input fields that can handle validation on their own. For example, if I create a “ColorPicker” component, I’d like it to automatically set it’s error message to “Invalid color” if the user enters an invalid color.

Basically, the only needed feature would be an additional property in the meta object given to Field customComponent, that would allow it to set its validity. So in addition to input.onChange, input.onBlur, … We could have either:

  • meta.setValidity: a connect-ed action creator that would set the validity / error message for the current field
  • meta.onValidate: or a validation method automatically called when the value is changed. Just like the validate property on reduxForm but at Field level

An other example of what it could provide, would be to write a form like this:

<MyForm>
  <MyTextField label="First name" name="firstName" required /> // <--- "required" is handled by TextField validation
  <MyTextField label="Country" name="country" validate={(value) => isValidCountry(value)} /> // <--- Custom validation at field level =)
</MyForm>

I think the current validation system is very limited and does not really take advantage of redux. If I wanted to add this feature with the current API I would need to wrap my form around an other HOC which would allow fields to register via context and automatically generate the validation function at form level. Or I could create a plugin to alter the state myself but I don’t think that’s a good solution.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
erikrascommented, Dec 8, 2016

Here you go!

Field-level validation in v6.3.0

2reactions
gaelolliviercommented, Nov 30, 2016

@davidkpiano Exactly like this ! I can’t find any way to implement this with the current API. I really think validation should be responsibility of the fields and not the form, or at least both options should be provided. I don’t like the idea of having to write a validate function that checks all my required fields for every form, when just a require on my input component would be enough.

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Field Level Form Validation - w3resource
We have created JavaScript functions (one for each input field whose value is to be validated) which check whether a value submitted by...
Read more >
Field-Level Validation Example - Redux Form
Then run npm run example:fieldLevelValidation or manually run the following commands: cd ./examples/fieldLevelValidation npm install npm start.
Read more >
field level validations in module pool programming
I want to perform validations on some fields in my module program.Please guide me how to do it.
Read more >
Form and Field Level Validations
ASSIST features field level validation on many form fields to ensure that they information being entered is in the proper format. ... In...
Read more >
How to Create a Validation Rule for a field in MS Access
How to Create a Validation Rule for a field in MS Access - Office 365. This video explains how you can create a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found