From 357f4adf715a58b17faa3b6094aef6b8f7de4391 Mon Sep 17 00:00:00 2001 From: Semigradsky Date: Thu, 9 Jul 2015 12:53:26 +0300 Subject: [PATCH] `getErrorMessages` should return empty array when there are no errors --- src/Mixin.js | 5 +++-- src/main.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Mixin.js b/src/Mixin.js index df655d7..d615fc7 100644 --- a/src/Mixin.js +++ b/src/Mixin.js @@ -140,10 +140,11 @@ module.exports = { return this.state._value !== ''; }, getErrorMessage: function () { - return this.getErrorMessages() && this.getErrorMessages()[0]; + var messages = this.getErrorMessages(); + return messages.length ? messages[0] : null; }, getErrorMessages: function () { - return !this.isValid() || this.showRequired() ? (this.state._externalError || this.state._validationError) : null; + return !this.isValid() || this.showRequired() ? (this.state._externalError || this.state._validationError || []) : []; }, isFormDisabled: function () { return this.context.formsy.isFormDisabled(); diff --git a/src/main.js b/src/main.js index 7cf016e..c0924a4 100644 --- a/src/main.js +++ b/src/main.js @@ -317,7 +317,8 @@ Formsy.Form = React.createClass({ } if (isRequired) { - return [validationErrors[requiredResults.success[0]]] || null; + var error = validationErrors[requiredResults.success[0]]; + return error ? [error] : null; } if (validationResults.failed.length) {