diff --git a/lib/phoenix_html/form.ex b/lib/phoenix_html/form.ex index 82c9944..ba324d9 100644 --- a/lib/phoenix_html/form.ex +++ b/lib/phoenix_html/form.ex @@ -252,6 +252,9 @@ defmodule Phoenix.HTML.Form do won't be ignored on submission. This requires however that the textarea is rendered with no spaces after its content + + * For "file", it returns an empty string because file path + can't be set programmatically. """ def normalize_value("datetime-local", %struct{} = value) when struct in [NaiveDateTime, DateTime] do @@ -268,6 +271,10 @@ defmodule Phoenix.HTML.Form do html_escape(value) == {:safe, "true"} end + def normalize_value("file", _value) do + "" + end + def normalize_value(_type, value) do value end diff --git a/test/phoenix_html/form_test.exs b/test/phoenix_html/form_test.exs index b8b2921..b0ab10b 100644 --- a/test/phoenix_html/form_test.exs +++ b/test/phoenix_html/form_test.exs @@ -115,6 +115,10 @@ defmodule Phoenix.HTML.FormTest do assert safe_to_string(normalize_value("textarea", nil)) == "\n" end + test "for file" do + assert normalize_value("file", "") == "" + end + test "for anything else" do assert normalize_value("foo", "") == "" end