From 802b517c0b2955d2d4c5185d45b033f4c30fe744 Mon Sep 17 00:00:00 2001 From: Biruk Haileye Tabor Date: Fri, 9 May 2025 12:55:37 +0300 Subject: [PATCH 1/2] Fix form file input normalized value Set form file input normalized value to empty string --- lib/phoenix_html/form.ex | 4 ++++ test/phoenix_html/form_test.exs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/phoenix_html/form.ex b/lib/phoenix_html/form.ex index 82c9944..c2f131e 100644 --- a/lib/phoenix_html/form.ex +++ b/lib/phoenix_html/form.ex @@ -268,6 +268,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 From 2c0eef2b38038aea0cbafd33dea89ee3ce7f0df1 Mon Sep 17 00:00:00 2001 From: Biruk Haileye Tabor Date: Sun, 22 Jun 2025 10:43:14 +0300 Subject: [PATCH 2/2] Add file input normalization documentation --- lib/phoenix_html/form.ex | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/phoenix_html/form.ex b/lib/phoenix_html/form.ex index c2f131e..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