Comments (6)
@tirli done, [email protected]
from neoform.
I got the idea and the issue... I'm not sure which types we should pass in validator, it feels more like NeoForm internals you shouldn't rely on. I'm thinking more about propagating a form-wide prop like isSubmitting
so you can choose which validator to use from outside.
const userNameValidator = (isSubmitting) => (value) => {
return isSubmitting ?
Promise.resolve('valid on submit') :
Promise.resolve('valid on some other event')
}
// ...
<MyInput name="user.name" validator={userNameValidator(isSubmitting)} />
I'm not quite sure that something like this will work because we need to render first with isSubmitting
, receive updated validator function and only after that validate the form, but I like the idea of making it more abstract and flexible in any way. What do you think? Or do you have an idea on how to pass those validator "types"?
from neoform.
Btw, we can internally call validator with field
or form
"types", right from formValidation:
validateField(name) {
// ...
validator(value, 'field')
// ...
}
validateForm(successHandler, errorHandler) {
// ...
return validator(value, 'form')
// ...
}
It's more about source or reason of validation than a type, but it's still the easiest fix.
from neoform.
It seems like the first one wouldn't work because there is still only one validator. So closure wouldn't help.
The second approach is better, but it wouldn't work if I need to detect if it blur or change or some other event.
I think that we can add an argument to validate
method. Most of the cases it's used like
<input onChange={validate} />
so it will be getting an event. So we can use event.type
inside or if it was called directly by user he should provide a { type: 'myCustomAction'}
of just nothing. What is more, the same thing we can make with submitting. Add it as a custom type.
from neoform.
Sorry I still don't have much time to work on NeoForm :( Your PR is merged, but I'm going to release it together with #11
from neoform.
@deepsweet If it possible, can you please release it before? So it wouldn't be blocking me and you won't need to fix #11 as soon as possible and can fix it when you'll have time
from neoform.
Related Issues (9)
- Correct peer dependencies HOT 2
- Neoform doesn't work with [email protected] HOT 4
- Validation is out of sync with input HOT 2
- Hmmmm HOT 2
- Issue with FieldValidation HOT 7
- Add typings support HOT 1
- Validation Requirement changes HOT 2
- Dependency on recompose HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from neoform.