我知道Phoenix
提供了一些不错的 Railsy 助手,可以以如下形式使用:
text_input
number_input
date_select
- 和
submit
但我找不到select
字段。我一直在搜索Phoenix Docs,但找不到任何东西。
helper
所以我的问题是,表单中的选择字段是否有凤凰?
我知道Phoenix
提供了一些不错的 Railsy 助手,可以以如下形式使用:
text_input
number_input
date_select
submit
但我找不到select
字段。我一直在搜索Phoenix Docs,但找不到任何东西。
helper
所以我的问题是,表单中的选择字段是否有凤凰?
我应该一直在搜索Phoenix.HTML
文档(感谢José指出这一点!)
的助手select
是:
# Assuming form contains a User model
select(form, :age, 0..120)
#=> <select id="user_age" name="user[age]">
# <option value="0">0</option>
# ...
# <option value="120">120</option>
# </select>
select(form, :role, ["Admin": "admin", "User": "user"])
#=> <select id="user_role" name="user[role]">
# <option value="admin">Admin</option>
# <option value="user">User</option>
# </select>
select(form, :role, ["Admin": "admin", "User": "user"], prompt: "Choose your role")
#=> <select id="user_role" name="user[role]">
# <option value="">Choose your role</option>
# <option value="admin">Admin</option>
# <option value="user">User</option>
# </select>
它在那里,文档在 Phoenix.HTML 项目中:http: //hexdocs.pm/phoenix_html/