I have a Flask app in which I can populate form data by uploading a CSV file which is then read. I want to populate a FieldList with the data read from the CSV. However, whe
OK, I spent hours on this and in the end it was such a trivial code change.
Most fields let you change their value by modifying the data attribute (as I was doing above). In fact, in my code, I had this comment as above:
### either of these ways have the same end result.
#
# studentform = StudentForm()
# studentform.student_id.data = student_id
# studentform.student_name.data = name
#
### OR
#
# student_data = MultiDict([('student_id',student_id), ('student_name',name)])
# studentform = StudentForm(student_data)
However, in the case of a FieldList of FormFields, we should not edit the data attribute, but rather the field itself. The following code works as expected:
for student_id, name in student_info:
studentform = StudentForm()
studentform.student_id = student_id # not student_id.data
studentform.student_name = name
classform.students.append_entry(studentform)
I hope this helps someone experiencing the same problem.