web2py 自动填充/自动完成返回 id
我有一个 from,我想根据数据库和填充字段中的信息自动填充它:
在 db_wizard.py 中,
db.define_table('receiver',
Field('name'), # e.g. Daniel
Field('email'),# e.g. [email protected]
Field('opening'), # e.g. Dear Daniel
...)
db.define_table('sender',
Field('name'), # e.g. John
Field('email'), # e.g. [email protected]
Field('tel'), # e.g. 111 222 111
...)
db.define_table('letter',
Field('sender', db.sender.id), # e.g. Daniel
Field('receiver', db.receiver.id), # e.g. John
Field('opening'), # should be filled automatically when choosing/changing the value of "receiver"
...)
我使用plugin_lazy_widget
db.letter.opening.widget = suggest_widget(db.receiver.opening, id_field=db.i2l_receiver_profile.id,
limitby=(0,10), min_length=1, db=db(db.i2l_receiver_profile.user_id==auth.user_id))
,但此小部件甚至 web2py_autocomplete_widget 始终返回的 ID
选择记录!而不是我们真正放入“opening”中的内容,如上面的示例:它返回 1
而不是 Dear Daniel
i've a from and i want to fill it automatically based on information from a database and filled fields :
in db_wizard.py
db.define_table('receiver',
Field('name'), # e.g. Daniel
Field('email'),# e.g. [email protected]
Field('opening'), # e.g. Dear Daniel
...)
db.define_table('sender',
Field('name'), # e.g. John
Field('email'), # e.g. [email protected]
Field('tel'), # e.g. 111 222 111
...)
db.define_table('letter',
Field('sender', db.sender.id), # e.g. Daniel
Field('receiver', db.receiver.id), # e.g. John
Field('opening'), # should be filled automatically when choosing/changing the value of "receiver"
...)
i use the plugin_lazy_widget
db.letter.opening.widget = suggest_widget(db.receiver.opening, id_field=db.i2l_receiver_profile.id,
limitby=(0,10), min_length=1, db=db(db.i2l_receiver_profile.user_id==auth.user_id))
but this widget or even the web2py_autocomplete_widget returns always the ID
of the chosen record! and not what we really put in "opening", like the example above: it returns 1
and not Dear Daniel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您不想使用 suggest_widget (或内置的自动完成小部件)。相反,您希望在用户选择接收者后立即动态填充“开放”字段。为此,您可能需要 lazy_options_widget 的修改版本(不与 suggest_widget 一起使用) 。
另请注意,使用带有“opening”字段的 id_field 无论如何都是不合适的,因为它不是引用字段(因此没有关联的 id 可供引用)。
I don't think you want to use the suggest_widget (or the built-in autocomplete widget). Instead, you want the 'opening' field dynamically filled in as soon as the user selects a receiver. For that, you probably need a modified version of the lazy_options_widget (not used in conjunction with the suggest_widget).
Also, note that using an id_field with the 'opening' field wouldn't be appropriate anyway because it is not a reference field (so there is no associated id to reference).
相反:
使用:
这意味着不定义“
id_field
”将阻止它instead :
use:
that means not defining "
id_field
" will prevent it