Rails Active Admin 选择或新建
我有一个产品列表,并且有一个与该产品相关的供应商。因此,当您添加产品时,从下拉列表中选择供应商。但如果供应商不存在,我希望用户能够通过下拉框旁边的+图标添加新供应商,该下拉框会打开一个包含供应商/新的新选项卡。我研究过 select2 插件,但它没有给我我需要的东西。
I have a list of products and i have a supplier associated with the product. So when you add the product select the supplier from a dropdown. But If the supplier doesn't exist, i want the ability for the user to add a new supplier via a + icon next to the dropdown box which opens a new tab with suppliers/new. I've looked into the select2 addon, but it doesn't give me what I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
https://select2.org/tagging
请查看 select2 的动态选项创建。然而文档很难理解。
也许你可以考虑在这种情况下使用模态。
https://select2.org/tagging
Please look at the select2's dynamic option creation. However documentation is hard to understand.
May be you can think of using modals like this type of situations.
我用
activeadmin_addons
gem 解决了这个问题。默认情况下,它会将选择字段转换为 select2,并且使用tags
选项,您可以创建新选项:app/admin/products.rb
我希望 Select2 能够选择新选项时发送创建请求,但是,它将在
supplier_id
参数中发送新选项的名称。尽管如此,我们可以使用它:app/admin/products.rb
I solved this with the
activeadmin_addons
gem. It turns select fields into select2 by default and with thetags
option you can enable the creation of new options:app/admin/products.rb
I would've expected Select2 to send a create request when selecting a new option, however, it will send the name of the new option in the
supplier_id
param. Nevertheless we can work with that:app/admin/products.rb