ForEach(Array(vm.numberOfResistors.enumerated()), id: .offset) { index, resistor in
UnitTextField(
title: "Resistor (index + 1)",
value: $dummyVM.numberOfResistors[index].valueString,
unit: $dummyVM.numberOfResistors[index].unit,
focusField: $focusField,
fieldType: "resistor (index + 1)"
).onSubmit {
if index <= vm.numberOfResistors.count {
print(index)
focusField = "resistor (index + 1)"
} else {
print("2")
focusField = nil
}
}.onChange(of: resistor) { oldValue, newValue in
vm.numberOfResistors[index].value = Constants.convertToCoulomb(from: resistor.unit, value: Double(newValue.valueString) ?? 0)
}
}.padding(.bottom)
I’m trying to use an onSubmit inside na enumerated for loop, however for some reason the index is always 0, it does work perfectly fine one next onChange, why is that?