Wtforms Selectfield With Dynamic Choices Always Returns "none" For Data
I am new to wtforms. I have to provide user with list of fruits and cost of each fruit as shown below, Total number of fruits are dynamically generated and each fruit prices is al
Solution 1:
I resolved the issue!
After user submits the form, I am receiving the submitted values properly, but in populate_fruits_list() method, I am making the list empty by removing the elements from the list, using pop_entry(). Once the list is empty, I am adding the elements to the list again. Because of the deletion of list elements, user selection to this field is resetting to "None".
Answer : After the form was submitted, if there are any fields which are populated dynamically, we shouldn't delete the entries from the list instead we can reassign the values using index like arr[0] = value.
i.e., replaced below statements
arr.popentry()
arr.append(value)
with
arr[i] = value //where i is an index
Hope this information will be helpful to others.
- Sravan
Post a Comment for "Wtforms Selectfield With Dynamic Choices Always Returns "none" For Data"