Fill two other fields of a formset depending on au

2019-07-21 06:37发布

I would like to fill two other fields automatically depending upon the selection someone makes in an autocomplete field, using django-autocomplete-light. However, my java script is not that good, so I don't really know where to start. Any help is very much appreciated.

User submit their publicized papers. There is a "person" autocomplete field in a formset (its a many to many relation for authors and other people that worked towards the publication). If a user chooses a person, I want that persons name and family name automatically filled in two other fields in that formset, so that users can make changes (also, it is a prerequisite from the data modell). Same if they change or delete the selected person.

Screenshot of formset

I thought best would be to have a view for name and a view for family name in order to retrieve those two with the id I could get from the autocomplete field.

However, how do I do the asynchronous retrieval of the names and fill them into the two fields?

Thank you!

Best Teconomix

1条回答
太酷不给撩
2楼-- · 2019-07-21 07:06

there is something called forward attribute that you can mention in your form field in autocomplete light with that you can load values for your two fields but i still don't know how to make them selected
https://django-autocomplete-light.readthedocs.io/en/master/tutorial.html#filtering-results-based-on-the-value-of-other-fields-in-the-form

查看更多
登录 后发表回答