no need to have blank 'errors' property in the states. validation plugin now handles that

This commit is contained in:
Edin Dazdarevic
2015-03-04 22:55:16 +01:00
parent 38de717da9
commit b47a90b476
4 changed files with 7 additions and 5 deletions

View File

@@ -11,7 +11,7 @@ var RibicaValidationMixin = {
_validate: function(prop, value) {
if(this.validations && this.validations[prop]) {
var cb = function(err, revalidateFields) {
var errors = this.state.errors;
var errors = this.state.errors || {};
if (err !== undefined) {
if(err.length > 0) {
errors[prop] = err;
@@ -44,7 +44,8 @@ var RibicaValidationMixin = {
},
getValidationMessages:function(prop) {
return (this.state.errors[prop] || []);
var errors = this.state.errors || {};
return (errors[prop] || []);
},
validateField: function(field) {
this._validate(field, this.state[field]);
@@ -58,7 +59,8 @@ var RibicaValidationMixin = {
return this.isValid();
},
isValid: function() {
return Object.keys(this.state.errors).length === 0;
var errors = this.state.errors || {};
return Object.keys(errors).length === 0;
},
componentDidMount : function(){
if (this.validations) {