Fill two other fields of a formset depending on autocomplete selection

1.1k views Asked by At

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

2

There are 2 answers

0
rsb On

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

1
Dermadr On

Write views and models and HTML