diff --git a/modules/st2-auto-form/fields/array.js b/modules/st2-auto-form/fields/array.js index 3810ed756..8bb6c059c 100644 --- a/modules/st2-auto-form/fields/array.js +++ b/modules/st2-auto-form/fields/array.js @@ -27,6 +27,10 @@ const jsonCheck = (value) => { return true; }; +const jsonInArrayCheck = (value) => { + return value.every(item => typeof(item) === 'object' ); +}; + const typeChecks = (type, value) => { const v = String(value); switch (type) { @@ -35,7 +39,7 @@ const typeChecks = (type, value) => { case 'integer': return !validator.isInt(v) && `'${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; @@ -111,6 +115,10 @@ export default class ArrayField extends BaseTextField { return v; } + if (Array.isArray(v) && jsonInArrayCheck(v)) { + return JSON.stringify(v); + } + const { secret } = this.props.spec || {}; if (secret && v && !Array.isArray(v)) {