Hi everyone, I just published a new project: Shaking React Form, to help build react forms with validations easily. I Hope you’d love to use and help maintain and develop.
a tiny demo:
import ShackingForm from 'shaking-react-form';
import RawShakingReactFormField from 'raw-shaking-react-form-field';
const schemas = {
username: {
label: 'Username',
validate(v){
if (!v) return 'username is required'
},
options: {
placeholder: 'input username'
}
},
password: {
label: 'Password',
type: 'password',
validate(v){
if (!v || v.length < 6) return 'password cannot be less than 6 letters'
}
},
}
class SomeReactComponent extends React.Component {
// you can save form values as you like, here is just for convenience saving them directly into state
constructor(props) {
super(props);
this.state = {};
Object.keys(schemas).forEach(key=>this.state[key] = null);
}
render() {
return <div>
<ShackingForm
schemas={schemas}
values={this.state}
onChange={(values)=>{this.setState(values)}}
onSubmit={(values)=>console.log('submit', values)}
onErrors={(errors)=>console.log('errors', errors)}
fieldClass={RawShakingReactFormField}
>
<button type="submit">Submit</button>
</ShackingForm>
</div>
}
}