From 5cc979e2490ee0ae67465c6da25a1410a3ec0976 Mon Sep 17 00:00:00 2001 From: Bryan Naegele Date: Mon, 2 Mar 2015 13:08:08 -0600 Subject: [PATCH] Dynamic validation support Add dynamic validation support --- src/main.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main.js b/src/main.js index 98f0eae..f0a8b91 100644 --- a/src/main.js +++ b/src/main.js @@ -127,13 +127,7 @@ Formsy.Mixin = { componentWillMount: function () { var configure = function () { - // Add validations to the store itself as the props object can not be modified - this._validations = this.props.validations || ''; - - if (this.props.required) { - this._validations = this.props.validations ? this.props.validations + ',' : ''; - this._validations += 'isValue'; - } + this.setValidations(); this.props._attachToForm(this); }.bind(this); @@ -158,6 +152,7 @@ Formsy.Mixin = { nextProps._attachToForm = this.props._attachToForm; nextProps._detachFromForm = this.props._detachFromForm; nextProps._validate = this.props._validate; + this.setValidations(); }, componentDidUpdate: function(prevProps, prevState) { @@ -177,6 +172,16 @@ Formsy.Mixin = { this.props._detachFromForm(this); }, + setValidations: function() { + // Add validations to the store itself as the props object can not be modified + this._validations = this.props.validations || ''; + + if (this.props.required) { + this._validations = this.props.validations ? this.props.validations + ',' : ''; + this._validations += 'isValue'; + } + }, + // We validate after the value has been set setValue: function (value) { this.setState({