From 2e392ae542a0c202bbe21a26628890c2000e77b5 Mon Sep 17 00:00:00 2001 From: jmeyer Date: Tue, 14 May 2019 14:45:10 -0600 Subject: [PATCH 1/2] initial fix of array of object field validation issue --- modules/st2-auto-form/fields/array.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/st2-auto-form/fields/array.js b/modules/st2-auto-form/fields/array.js index d77a088e5..4df3bde5e 100644 --- a/modules/st2-auto-form/fields/array.js +++ b/modules/st2-auto-form/fields/array.js @@ -17,11 +17,11 @@ const typeChecks = (type, value) => { const v = String(value); switch (type) { case 'number': - return !validator.isFloat(v) && `'${v}' is not a number`; + return !validator.isFloat(value) && `'${v}' is not a number`; case 'integer': - return !validator.isInt(v) && `'${v}' is not an integer`; + return !validator.isInt(value) && `'${v}' is not an integer`; case 'object': - return !_.isPlainObject(v) && `'${v}' is not an object`; + return !_.isPlainObject(value) && `'${v}' is not an object`; case 'string': default: return false; @@ -71,7 +71,7 @@ export default class ArrayField extends BaseTextField { } toStateValue(v) { - if (jsonCheck(v)) { + if (jsonCheck(v) || Array.isArray(v)) { return JSON.stringify(v); } From 15e02e5a59d1131314f6b823dbb8865754406182 Mon Sep 17 00:00:00 2001 From: jmeyer Date: Tue, 14 May 2019 16:13:00 -0600 Subject: [PATCH 2/2] fixing compatibility issue with type of string and number --- modules/st2-auto-form/fields/array.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/modules/st2-auto-form/fields/array.js b/modules/st2-auto-form/fields/array.js index 4df3bde5e..110892342 100644 --- a/modules/st2-auto-form/fields/array.js +++ b/modules/st2-auto-form/fields/array.js @@ -17,9 +17,9 @@ const typeChecks = (type, value) => { const v = String(value); switch (type) { case 'number': - return !validator.isFloat(value) && `'${v}' is not a number`; + return !validator.isFloat(v) && `'${v}' is not a number`; case 'integer': - return !validator.isInt(value) && `'${v}' is not an integer`; + return !validator.isInt(v) && `'${v}' is not an integer`; case 'object': return !_.isPlainObject(value) && `'${v}' is not an object`; case 'string': @@ -71,7 +71,7 @@ export default class ArrayField extends BaseTextField { } toStateValue(v) { - if (jsonCheck(v) || Array.isArray(v)) { + if (jsonCheck(v)) { return JSON.stringify(v); } @@ -79,6 +79,10 @@ export default class ArrayField extends BaseTextField { return v; } + if (Array.isArray(v) && this.props.spec.items.type === 'object') { + return JSON.stringify(v); + } + const { secret } = this.props.spec || {}; if (secret && v && !Array.isArray(v)) { return v;