Skip to content

Commit f97bf1a

Browse files
authored
Merge pull request #722 from jdmeyer3/bug/validate_array_of_obj
Bug/validate array of obj
2 parents 45960c3 + fdd6671 commit f97bf1a

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

modules/st2-auto-form/fields/array.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ const jsonCheck = (value) => {
2727
return true;
2828
};
2929

30+
const jsonInArrayCheck = (value) => {
31+
return value.every(item => typeof(item) === 'object' );
32+
};
33+
3034
const typeChecks = (type, value) => {
3135
const v = String(value);
3236
switch (type) {
@@ -35,7 +39,7 @@ const typeChecks = (type, value) => {
3539
case 'integer':
3640
return !validator.isInt(v) && `'${v}' is not an integer`;
3741
case 'object':
38-
return !_.isPlainObject(v) && `'${v}' is not an object`;
42+
return !_.isPlainObject(value) && `'${v}' is not an object`;
3943
case 'string':
4044
default:
4145
return false;
@@ -111,6 +115,10 @@ export default class ArrayField extends BaseTextField {
111115
return v;
112116
}
113117

118+
if (Array.isArray(v) && jsonInArrayCheck(v)) {
119+
return JSON.stringify(v);
120+
}
121+
114122
const { secret } = this.props.spec || {};
115123

116124
if (secret && v && !Array.isArray(v)) {

0 commit comments

Comments
 (0)