Skip to content

Commit

Permalink
Update <Form> to use <.form>
Browse files Browse the repository at this point in the history
  • Loading branch information
msaraiva committed Sep 6, 2021
1 parent fe76fb1 commit 5d6aadb
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
11 changes: 9 additions & 2 deletions lib/surface/components/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,19 @@ defmodule Surface.Components.Form do

assigns = assign(assigns, opts: opts)

# ~F"""
# {form = form_for(@for, @action, @opts)}
# <Context put={__MODULE__, form: form}>
# <#slot :args={form: form} />
# </Context>
# <#Raw></form></#Raw>
# """
~F"""
{form = form_for(@for, @action, @opts)}
<.form :let={form} for={@for} action={@action} {...@opts}>
<Context put={__MODULE__, form: form}>
<#slot :args={form: form} />
</Context>
<#Raw></form></#Raw>
</.form>
"""
end
end
4 changes: 2 additions & 2 deletions test/surface/components/form/checkbox_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ defmodule Surface.Components.Form.CheckboxTest do
end

assert html =~ """
<form action="#" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post">
<input name="_csrf_token" type="hidden" value="test">
<input name="user[admin]" type="hidden" value="false">\
<input id="user_admin" name="user[admin]" type="checkbox" value="true">
</form>
Expand Down
4 changes: 2 additions & 2 deletions test/surface/components/form/file_input_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ defmodule Surface.Components.Form.FileInputTest do
end

assert html =~ """
<form action="#" enctype="multipart/form-data" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post" enctype="multipart/form-data">
<input name="_csrf_token" type="hidden" value="test">
<input id="user_picture" name="user[picture]" type="file">
</form>
"""
Expand Down
8 changes: 4 additions & 4 deletions test/surface/components/form/hidden_inputs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ defmodule Surface.Components.Form.HiddenInputsTest do
end

assert html =~ """
<form action="#" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post">
<input name="_csrf_token" type="hidden" value="test">
</form>
"""
end
Expand All @@ -37,8 +37,8 @@ defmodule Surface.Components.Form.HiddenInputsTest do
end

assert html =~ """
<form action="#" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post">
<input name="_csrf_token" type="hidden" value="test">
</form>
"""
end
Expand Down
16 changes: 8 additions & 8 deletions test/surface/components/form/inputs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ defmodule Surface.Components.Form.InputsTest do
end

assert html =~ """
<form action="#" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post">
<input name="_csrf_token" type="hidden" value="test">
<input id="parent_children_name" name="parent[children][name]" type="text">
<input id="parent_children_email" name="parent[children][email]" type="text">
</form>
Expand All @@ -65,8 +65,8 @@ defmodule Surface.Components.Form.InputsTest do
end

assert html =~ """
<form action="#" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post">
<input name="_csrf_token" type="hidden" value="test">
<div>index: <span>0</span></div>
<div>index: <span>1</span></div>
</form>
Expand All @@ -87,8 +87,8 @@ defmodule Surface.Components.Form.InputsTest do
end

assert html =~ """
<form action="#" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post">
<input name="_csrf_token" type="hidden" value="test">
<input id="parent_children_name" name="parent[children][name]" type="text">
<input id="parent_children_email" name="parent[children][email]" type="text">
</form>
Expand All @@ -109,8 +109,8 @@ defmodule Surface.Components.Form.InputsTest do
end

assert html =~ """
<form action="#" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post">
<input name="_csrf_token" type="hidden" value="test">
<input id="parent_children_name" name="custom_name[name]" type="text">
<input id="parent_children_email" name="custom_name[email]" type="text">
</form>
Expand Down
12 changes: 6 additions & 6 deletions test/surface/components/form_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ defmodule Surface.Components.FormTest do
end

assert html =~ """
<form action="#" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post">
<input name="_csrf_token" type="hidden" value="test">
</form>
"""
end
Expand All @@ -58,8 +58,8 @@ defmodule Surface.Components.FormTest do
end

assert html =~ """
<form action="#" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post">
<input name="_csrf_token" type="hidden" value="test">
<input id="user_name" name="user[name]" type="text">
</form>
"""
Expand All @@ -76,8 +76,8 @@ defmodule Surface.Components.FormTest do
end

assert html =~ """
<form action="#" method="post">\
<input name="_csrf_token" type="hidden" value="test">
<form action="#" method="post">
<input name="_csrf_token" type="hidden" value="test">
<input id="user_name" name="user[name]" type="text">
</form>
"""
Expand Down

0 comments on commit 5d6aadb

Please sign in to comment.