From 314eb5c09c819f9fa94016219a07389dd6bc9a73 Mon Sep 17 00:00:00 2001 From: Morad Faris Date: Sun, 7 Mar 2021 18:17:41 +0200 Subject: [PATCH] fix #710 --- modules/st2-auto-form/fields/array.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/st2-auto-form/fields/array.js b/modules/st2-auto-form/fields/array.js index 35e0e80b5..892031bf6 100644 --- a/modules/st2-auto-form/fields/array.js +++ b/modules/st2-auto-form/fields/array.js @@ -80,8 +80,15 @@ export default class ArrayField extends BaseTextField { const { items } = this.props.spec || {}; return split(v) - .map((v) => typeConversions(items && items.type, v)) - ; + .map((v) => { + const t = items && items.type; + if (t === 'object') { + try { + v = JSON.parse(v) + } catch (e) { } + } + return typeConversions(t, v) + }); } toStateValue(v) { @@ -114,7 +121,15 @@ export default class ArrayField extends BaseTextField { if (o && !_.isArray(o)) { return 'value is not an array'; } - const invalidItem = o.find((v) => typeChecks(items && items.type, v)); + const invalidItem = o.find((v) => { + const t = items && items.type; + if (t === 'object') { + try { + v = JSON.parse(v) + } catch (e) {} + } + return typeChecks(t, v) + }); return invalidItem && typeChecks(items && items.type, invalidItem); } catch(e) {