2016-05-12 17:42:04 -04:00
|
|
|
var classNames = require('classnames');
|
|
|
|
var Formsy = require('formsy-react');
|
2016-07-01 11:43:18 -04:00
|
|
|
var omit = require('lodash.omit');
|
2016-05-12 17:42:04 -04:00
|
|
|
var React = require('react');
|
2016-06-02 15:25:02 -04:00
|
|
|
var validations = require('./validations.jsx').validations;
|
2016-05-12 17:42:04 -04:00
|
|
|
|
|
|
|
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 {
|
2016-07-01 11:43:18 -04:00
|
|
|
noValidate: true,
|
|
|
|
onChange: function () {}
|
2016-05-13 18:48:21 -04:00
|
|
|
};
|
|
|
|
},
|
2016-07-01 11:43:18 -04:00
|
|
|
getInitialState: function () {
|
|
|
|
return {
|
|
|
|
allValues: {}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
onChange: function (currentValues, isChanged) {
|
|
|
|
this.setState({allValues: omit(currentValues, 'all')});
|
|
|
|
this.props.onChange(currentValues, isChanged);
|
|
|
|
},
|
2016-05-12 17:42:04 -04:00
|
|
|
render: function () {
|
|
|
|
var classes = classNames(
|
|
|
|
'form',
|
|
|
|
this.props.className
|
|
|
|
);
|
|
|
|
return (
|
2016-07-01 11:43:18 -04:00
|
|
|
<Formsy.Form {... this.props} className={classes} ref="formsy" onChange={this.onChange}>
|
2016-07-05 12:05:54 -04:00
|
|
|
{React.Children.map(this.props.children, function (child) {
|
|
|
|
if (child.props.name === 'all') {
|
|
|
|
return React.cloneElement(child, {value: this.state.allValues});
|
|
|
|
} else {
|
|
|
|
return child;
|
|
|
|
}
|
|
|
|
}.bind(this))}
|
2016-06-23 15:10:51 -04:00
|
|
|
</Formsy.Form>
|
2016-05-12 17:42:04 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Form;
|