Dynamic validation support
Add dynamic validation support
This commit is contained in:
parent
a72838b446
commit
5cc979e249
19
src/main.js
19
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({
|
||||
|
|
|
|||
Loading…
Reference in New Issue