Maria-Liakata-NLP-Group / annotations-interface

New iteration of the Annotations Interface tool
MIT License
0 stars 0 forks source link

How to update Flask forms in server side based on changes in client side? #41

Closed dsj976 closed 9 months ago

dsj976 commented 9 months ago

Currently using an AJAX call on the client side to update choices on a second select field based on changes to a first select field. These changes are only made on the client side (i.e. in the HTML), but are not propagated back to the server side (to the server's Flask form that creates the select field in the first place). This results in the error "TypeError: Choices cannot be None." from wtforms when calling the method validate_on_submit() of FlaskForm, because the form doesn't know about the changes that have taken place in the client side.

A temporary fix which seems to work, although ugly, has been implemented with commit b408fee. The choice of 1000 is to make sure that whatever update is made on the client side is accepted by the form on submission, as the update will fall in the range 0 to 1000. A better solution would be to update the select field attribute of the Flask form based on changes on the client side, but do not have time to investigate how to do this.

dsj976 commented 9 months ago

See commit 2ca8be2 - for context, see WTForms documentation. Commit ed17319 is nevertheless necessary as the Select Field in the Flask Form requires at least one choice on submission. This seems like a reasonable solution so closing this issue with these commits.