Dynamic validation support

Add dynamic validation support
This commit is contained in:
Bryan Naegele 2015-03-02 13:08:08 -06:00
parent a72838b446
commit 5cc979e249
1 changed files with 12 additions and 7 deletions

View File

@ -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({