How prepopulate text inputs with an initial value for $item?

I am implementing a form containing a set of repeated input fields which need to be initialized with some database values and then modified by user.

That is, we have a container in which set of items should be created:
item1: field1, field2,… fieldN
item2: field1, field2,… fieldN

I used a JavaScript expression to initialize the values in the form input:
`
var idx = $data.formInput.selectedItemIndex;

if (!$data.formInput.contractAdd.myItems) {
return null;
}

var itemData = $data.formInput.contractAdd.myItems[idx];

for(var i = 0; i < $data.bdmAllItems.length; i++) {
var bdmItem = $data.bdmAllItems[i];
if (bdmItem.id == itemData.itemId) {
// initializing the data on the form (in repeated container) with the DB settings
itemData.field1 = bdmItem.field1;
itemData.field2 = bdmItem.field2;
itemData.field3 = bdmItem.field3;
itemData.field4 = bdmItem.field4;
return bdmItem;
}
}

return null;`

Main issue is that after such initialization the input fields cannot be edited.

Is there an approach to resolve such issue? Please advise.