Add radio_button (#14)

This commit is contained in:
Shritesh Bhattarai 2019-08-13 10:04:14 -05:00 committed by Mitchell Hanberg
parent 408dfdc6c7
commit 43f10cd0de
4 changed files with 34 additions and 1 deletions

View file

@ -22,7 +22,7 @@ locals_without_parens = ~w[
checkbox color_input checkbox color_input date_input date_select datetime_local_input
datetime_select email_input file_input hidden_input number_input password_input range_input
search_input telephone_input textarea text_input time_input time_select url_input
reset submit phx_label multiple_select select phx_link phx_button
reset submit phx_label radio_button multiple_select select phx_link phx_button
]a |> Enum.map(fn e -> {e, :*} end)
[

View file

@ -2,6 +2,8 @@
## Master
- Import `radio_buttton/4`
## 0.1.2
### Bugfixes

View file

@ -219,6 +219,18 @@ defmodule Temple.Form do
end
end
@doc """
Please see `Phoenix.HTML.Form.radio_button/4` for details.
"""
defmacro radio_button(form, field, value, attrs \\ []) do
quote do
{:safe, input} =
Phoenix.HTML.Form.radio_button(unquote_splicing([form, field, value, attrs]))
Utils.put_buffer(var!(buff, Temple.Tags), input)
end
end
@doc """
Please see `Phoenix.HTML.Form.multiple_select/4` for details.
"""

View file

@ -394,6 +394,25 @@ defmodule Temple.FormTest do
assert result =~ ~s{name="bob"}
end
test "generates a radio button" do
conn = %Plug.Conn{}
action = "/"
opts = []
{:safe, result} =
temple do
form_for conn, action, opts do
radio_button(form, :bob, "1", class: "radio-styles")
end
end
assert result =~ ~s{<input}
assert result =~ ~s{type="radio"}
assert result =~ ~s{class="radio-styles"}
assert result =~ ~s{name="bob"}
assert result =~ ~s{value="1"}
end
test "generates a text_area/2" do
conn = %Plug.Conn{}
action = "/"