Skip to content

Commit

Permalink
Merge pull request #10 from saicheck2233/issue#121
Browse files Browse the repository at this point in the history
issue#121: remove `eval` func
  • Loading branch information
saicheck2233 authored Jul 11, 2023
2 parents a355633 + 8e34ea9 commit 3c5560e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/js/brutusin-json-forms.js
Original file line number Diff line number Diff line change
Expand Up @@ -1292,13 +1292,24 @@ if (typeof brutusin === "undefined") {
}

function getInitialValue(id) {
var ret;
try {
eval("ret = initialValue" + id.substring(1));
} catch (e) {
ret = null;
var fields = id.substring(2).split('.');
var initialValueClone = initialValue;
for(var i = 0; i < fields.length; i++) {
var field = fields[i];
if (field != "") {
if (field.substring(field.length - 1) === "]") {
//Get the index from the array in the field
var arrayIndex = parseInt(field.substring(field.lastIndexOf("[") + 1, field.length - 1));
//Substring off the square bracket from the field
field = field.substring(0, field.lastIndexOf("["));
initialValueClone = initialValueClone[field][arrayIndex];
} else {
initialValueClone = initialValueClone[field];
}
}
}
return ret;

return initialValueClone;
}

function getValue(schema, input) {
Expand Down

0 comments on commit 3c5560e

Please sign in to comment.