zero-plus-x / neoform Goto Github PK
View Code? Open in Web Editor NEW:white_check_mark: React form state management and validation
Home Page: https://www.webpackbin.com/bins/-KrbNqAfDYNwm07UmzTb
License: MIT License
:white_check_mark: React form state management and validation
Home Page: https://www.webpackbin.com/bins/-KrbNqAfDYNwm07UmzTb
License: MIT License
Please add support for typescript declarations to neoform
Hi,
This is my first time reporting an issue so apologies if it's none too legible. I'm having an issue with the FieldValidation function that is used to wrap the exported input element, as follows.
I'm seeing the type error as follows:
Please may you advise on the best course of action? Thanks for the package by the way! It's been a great help.
PS: Attached below is the input in its entirety, if that helps.
import React from 'react';
import { Field } from 'neoform';
import TextField from 'material-ui/TextField';
import { FieldValidation } from 'neoform-validation';
const TextInput = ({
autoComplete,
type,
defaultValue,
className,
floatingLabelText,
value,
onChange,
rows,
disabled,
hintText,
validate
}) => (
<TextField
autoComplete={autoComplete}
type={type}
value={value}
onChange={(e) => onChange(e.target.value)}
rows={rows}
disabled={disabled}
hintText={hintText}
floatingLabelText={floatingLabelText}
className={className}
defaultValue={defaultValue}
onBlur={validate}
/>
);
export default Field(FieldValidation(TextInput));
See also this gist
Proposed solution setTimeout(() => validate(), 0)
: perform validation at the next turn of event loop.
It would be nice to solve the out of sync issue
inside the neoform package.
Caret version ranges specified for versions 0.x only allows patch updates. neoform-plain-object-helpers
, neoform-plain-object-helpers
, and neoform-validation
all need version ranges compatible with neoform
0.3.
I had an situation where the validator
passed to thefield
had to change depending on other changes in other parts of the form
.
Unfortunately, since we register the validator
function once during componentDidMount
, it can't pick up changes in the validator
function. https://github.com/zero-plus-x/neoform/blob/master/packages/neoform-validation/src/fieldValidation.js#L18
I had to implement componentWillReceiveProps
in the fieldValidation
to check if there are any differences in the validator
function and register the new function.
componentWillReceiveProps(nextProps) {
if (nextProps.validator && nextProps.validator !== this.props.validator) {
this.context.neoform.registerValidator(this.props.name, nextProps.validator);
}
}
I might be doing this wrong, I will be glad if there is another way. Thanks.
^^^
Hi,
It seems like I cannot detect in validator function which event fired it. For example, I have an email field which is checked for validity(has @) onChange and it also has async validation which checks if it's allowed to use such email. Both this checks related to email field, so with the current approach it will look like that:
function validateEmailField(value) {
return Promise.all(emailValidator(value), availabilityValidator(value));
}
though I don't need to check availability on each change. I want to check it on submit like that
function validateEmailField(value, type) {
const validates = [];
switch (type) {
case 'change':
validates.push(emailValidator(value));
break;
case 'submit':
validates.push(availabilityValidator(value));
break;
default:
break;
}
return Promise.all(validates);
}
So I think it would be great if you (or I can create PR) will add support for event types to this call
./node_modules/neoform/es/form.js
14:16-34 'recompose' does not contain an export named 'createEagerFactory'.
I upgraded recompose in my project to version 0.26 and I'm getting this error.
I see that both neoform and neoform-validation depends on recompose. It was a recompact before. Why have you changed that?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.