scratch-www/src/components/forms/form.jsx

43 lines
1.2 KiB
React
Raw Normal View History

var classNames = require('classnames');
var Formsy = require('formsy-react');
var omit = require('lodash.omit');
var React = require('react');
2016-06-06 10:10:27 -04:00
var GeneralError = require('./general-error.jsx');
2016-06-02 15:25:02 -04:00
var validations = require('./validations.jsx').validations;
for (var validation in validations) {
Formsy.addValidationRule(validation, validations[validation]);
}
var Form = React.createClass({
2016-05-13 18:48:21 -04:00
getDefaultProps: function () {
return {
noValidate: true,
onChange: function () {}
2016-05-13 18:48:21 -04:00
};
},
getInitialState: function () {
return {
allValues: {}
};
},
onChange: function (currentValues, isChanged) {
this.setState({allValues: omit(currentValues, 'all')});
this.props.onChange(currentValues, isChanged);
},
render: function () {
var classes = classNames(
'form',
this.props.className
);
return (
<Formsy.Form {... this.props} className={classes} ref="formsy" onChange={this.onChange}>
<GeneralError name="all" value={this.state.allValues} />
2016-06-23 15:10:51 -04:00
{this.props.children}
</Formsy.Form>
);
}
});
module.exports = Form;