Skip to content

Commit 3c5560e

Browse files
authored
Merge pull request #10 from saicheck2233/issue#121
issue#121: remove `eval` func
2 parents a355633 + 8e34ea9 commit 3c5560e

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/js/brutusin-json-forms.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,13 +1292,24 @@ if (typeof brutusin === "undefined") {
12921292
}
12931293

12941294
function getInitialValue(id) {
1295-
var ret;
1296-
try {
1297-
eval("ret = initialValue" + id.substring(1));
1298-
} catch (e) {
1299-
ret = null;
1295+
var fields = id.substring(2).split('.');
1296+
var initialValueClone = initialValue;
1297+
for(var i = 0; i < fields.length; i++) {
1298+
var field = fields[i];
1299+
if (field != "") {
1300+
if (field.substring(field.length - 1) === "]") {
1301+
//Get the index from the array in the field
1302+
var arrayIndex = parseInt(field.substring(field.lastIndexOf("[") + 1, field.length - 1));
1303+
//Substring off the square bracket from the field
1304+
field = field.substring(0, field.lastIndexOf("["));
1305+
initialValueClone = initialValueClone[field][arrayIndex];
1306+
} else {
1307+
initialValueClone = initialValueClone[field];
1308+
}
1309+
}
13001310
}
1301-
return ret;
1311+
1312+
return initialValueClone;
13021313
}
13031314

13041315
function getValue(schema, input) {

0 commit comments

Comments
 (0)