根据自动完成选择,填写表单集的其他两个字段 [英] Fill two other fields of a formset depending on autocomplete selection

查看:96
本文介绍了根据自动完成选择,填写表单集的其他两个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据某人在自动完成字段中所做的选择自动使用django-autocomplete-light来填充其他两个字段.但是,我的Java脚本不是很好,所以我真的不知道从哪里开始.非常感谢您的帮助.

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.

我认为最好是有一个名字视图和一个姓氏视图,以便检索我可以从自动完成字段中获得的那两个ID.

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?

谢谢!

最佳 Teconomix

Best Teconomix

推荐答案

您可以在表单字段中以自动填充的方式提及前向属性,可以为两个字段加载值,但是我仍然不知道知道如何选择它们

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

这篇关于根据自动完成选择,填写表单集的其他两个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆