From a56f994886db4a32bccfcbd914e90d3aeadc535b Mon Sep 17 00:00:00 2001 From: Ray Schamp Date: Fri, 1 Jul 2016 11:43:18 -0400 Subject: [PATCH] Revalidate address step after invalid submissions I don't like that the state is being set to a calculation of existing props. When I did that calculation in `render`, it didn't update when fields were changed. Fixes #645 --- src/components/forms/form.jsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/components/forms/form.jsx b/src/components/forms/form.jsx index 00c5487c4..d93495337 100644 --- a/src/components/forms/form.jsx +++ b/src/components/forms/form.jsx @@ -1,5 +1,6 @@ var classNames = require('classnames'); var Formsy = require('formsy-react'); +var omit = require('lodash.omit'); var React = require('react'); var GeneralError = require('./general-error.jsx'); var validations = require('./validations.jsx').validations; @@ -11,17 +12,27 @@ for (var validation in validations) { var Form = React.createClass({ getDefaultProps: function () { return { - noValidate: true + noValidate: true, + onChange: function () {} }; }, + 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 ( - - + + {this.props.children} );