From 7fb17a752de0b35b43795e93c2129401599b38cf Mon Sep 17 00:00:00 2001 From: Bryan Naegele Date: Mon, 2 Mar 2015 13:22:11 -0600 Subject: [PATCH] Dynamic validations and requiring Allow validations to be updated, including requiring --- src/main.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.js b/src/main.js index f0a8b91..c6d7fff 100644 --- a/src/main.js +++ b/src/main.js @@ -127,7 +127,7 @@ Formsy.Mixin = { componentWillMount: function () { var configure = function () { - this.setValidations(); + this.setValidations(this.props.validations, this.props.required); this.props._attachToForm(this); }.bind(this); @@ -152,7 +152,7 @@ Formsy.Mixin = { nextProps._attachToForm = this.props._attachToForm; nextProps._detachFromForm = this.props._detachFromForm; nextProps._validate = this.props._validate; - this.setValidations(); + this.setValidations(nextProps.validations, nextProps.required); }, componentDidUpdate: function(prevProps, prevState) { @@ -172,12 +172,12 @@ Formsy.Mixin = { this.props._detachFromForm(this); }, - setValidations: function() { + setValidations: function(validations, required) { // Add validations to the store itself as the props object can not be modified - this._validations = this.props.validations || ''; + this._validations = validations || ''; - if (this.props.required) { - this._validations = this.props.validations ? this.props.validations + ',' : ''; + if (required) { + this._validations = validations ? validations + ',' : ''; this._validations += 'isValue'; } },