Validation forms
yarn or npm install validate
npm run build
- produces production version of your library under thelib
foldernpm run dev
- produces development version of your library and runs a watchernpm run test
- well ... it runs the tests :)npm run test:watch
- same as above but in a watch mode
- React
import React, { Component } from 'react';
import { createValidation, success, failure } from 'validate';
...
class TodoCreator extends Component {
isEmpty = (n, input, msg) => {
return n === '' ? failure([{ key: input, val: msg }]) : success();
}
handlerInput = ({ target }) => {
const { name, value } = target;
const errors = createValidation().ap(isEmpty('name1', name, 'is empty'))
.ap(isEmpty('name2', name, 'is empty'))
.orElse(new Map())
.chain(e => e);
this.setState({ [name]: value, errors: errors });
}
render() {
return (
<form>
<label>Name</label>
<input name="name" onChange={this.handlerInput} />
</form>
);
}
}
...
https://drboolean.gitbooks.io/mostly-adequate-guide/content/ https://github.com/concretesolutions/pareto.js/tree/master