Alright, I've found the solution.
What I did was to re-add every event listener whenever I needed a new one, by replacing
text = getInput(pieceidx);
getInput(pieceidx).addEventListener('focus', function() {text = getInput(pieceidx); });
addListeners(text);
with
for (i = 0; i <= pieceidx; i++) {
text = getInput(i);
getInput(pieceidx).addEventListener('focus', function() {text = getInput(pieceidx); });
addListeners(i);
}