Getting protocol Phoenix.HTML.Safe not implemented with "Ash Phoenix"
Protocol.UndefinedError at GET /profile
protocol Phoenix.HTML.Safe not implemented for type AshPhoenix.Form (a struct)
Got value:
#AshPhoenix.Form<
resource: ObanDashboard.UserProfile,
action: :create,
type: :create,
params: %{
user_id: "3b06a43b-d8af-4500-b5b9-fcbcb15168f3",
firstname: "",
lastname: "",
timezone: "Etc/UTC"
},
source: #Ash.Changeset<
domain: ObanDashboard.Domain,
action_type: :create,
action: :create,
attributes: %{timezone: "Etc/UTC"},
relationships: %{},
errors: [],
data: %ObanDashboard.UserProfile{
user: #Ash.NotLoaded<:relationship, field: :user>,
meta: #Ecto.Schema.Metadata<:built, "user_profiles">,
id: nil,
user_id: nil,
firstname: nil,
lastname: nil,
timezone: "Etc/UTC",
inserted_at: nil,
updated_at: nil
},
valid?: true
>,
name: "user_profile",
data: nil,
form_keys: [],
forms: %{},
domain: ObanDashboard.Domain,
method: "post",
submit_errors: nil,
id: "user_profile",
transform_errors: nil,
original_data: nil,
transform_params: nil,
prepare_params: nil,
prepare_source: nil,
raw_params: %{
user_id: "3b06a43b-d8af-4500-b5b9-fcbcb15168f3",
firstname: "",
lastname: "",
timezone: "Etc/UTC"
},
warn_on_unhandled_errors?: true,
any_removed?: false,
added?: false,
changed?: false,
touched_forms: MapSet.new([:user_id, :firstname, :lastname, :timezone]),
valid?: true,
errors: nil,
submitted_once?: false,
just_submitted?: false,
...
>
32 Replies
what code is causing this error?
<.simple_form for={@phoenix_form} phx-submit="save">
<.input
form={@phoenix_form}
name="user_profile[email]"
value={@user.email}
field={:email}
label="Email"
readonly
class="w-full px-3 py-2 border rounded bg-gray-100"
/>
<.input
form={@phoenix_form}
name="user_profile[firstname]"
value={(@profile && @profile.firstname) ""}
field={:firstname}
label="First Name"
class="w-full px-3 py-2 border rounded"
/>
<.input
form={@phoenix_form}
name="user_profile[lastname]"
value={(@profile && @profile.lastname) ""}
field={:lastname}
label="Last Name"
class="w-full px-3 py-2 border rounded"
/>
<.input
form={@phoenix_form}
name="user_profile[timezone]"
value={(@profile && @profile.timezone) || ""}
field={:timezone}
type="select"
options={@timezones}
label="Timezone"
class="w-full px-3 py-2 border rounded"
/>
<:actions>
<.button class="mt-4 bg-indigo-600 text-white px-4 py-2 rounded">
Save
</.button>
</:actions>
</.simple_form>
you're going to have to narrow it down, what line of code does the error point to?
defprotocol Phoenix.HTML.Safe do first line I am getting this error
can you paste the stacktrace from the error?
(phoenix_html 4.2.1) lib/phoenix_html/safe.ex:1: Phoenix.HTML.Safe.impl_for!/1
(phoenix_html 4.2.1) lib/phoenix_html/safe.ex:15: Phoenix.HTML.Safe.to_iodata/1
(phoenix_html 4.2.1) lib/phoenix_html.ex:244: Phoenix.HTML.build_attrs/1
(phoenix_html 4.2.1) lib/phoenix_html.ex:197: Phoenix.HTML.attributes_escape/1
(oban_dashboard 0.1.0) lib/oban_dashboard_web/components/core_components.ex:402: anonymous fn/2 in ObanDashboardWeb.CoreComponents."input (overridable 1)"/1
(oban_dashboard 0.1.0) /Users/amf-elixir-2025/oban_dashboard/lib/oban_dashboard_web/live/user_profile_live.ex:109: ObanDashboardWeb.UserProfileLive.render/1
(elixir 1.18.1) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 1.0.11) lib/phoenix_live_view/diff.ex:412: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 1.0.11) lib/phoenix_live_view/diff.ex:555: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.18.1) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 1.0.11) lib/phoenix_live_view/diff.ex:412: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 1.0.11) lib/phoenix_live_view/diff.ex:555: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.18.1) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 1.0.11) lib/phoenix_live_view/diff.ex:412: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 1.0.11) lib/phoenix_live_view/diff.ex:555: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
(elixir 1.18.1) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 1.0.11) lib/phoenix_live_view/diff.ex:412: Phoenix.LiveView.Diff.traverse/7
(phoenix_live_view 1.0.11) lib/phoenix_live_view/diff.ex:555: anonymous fn/4 in Phoenix.LiveView.Diff.traverse_dynamic/7
these lines - what's on those?
<.input
form={@phoenix_form}
name="user_profile[email]"
value={@user.email}
field={:email}
label="Email"
readonly
class="w-full px-3 py-2 border rounded bg-gray-100"
/> -- 109
core components - 402 "<input
type={@type}
name={@name}
id={@id}
value={Phoenix.HTML.Form.normalize_value(@type, @value)}
class={[
"mt-2 block w-full rounded-lg text-zinc-900 focus:ring-0 sm:text-sm sm:leading-6",
@errors == [] && "border-zinc-300 focus:border-zinc-400",
@errors != [] && "border-rose-400 focus:border-rose-400"
]}
{@rest}
/>"
odd. how have you defined your form? did you call
to_form
on it before rendering?form =
if profile do
AshPhoenix.Form.for_update(profile, :update,
as: "user_profile",
api: ObanDashboard,
forms: [auto?: true],
params: params
)
else
AshPhoenix.Form.for_create(UserProfile, :create,
as: "user_profile",
api: ObanDashboard,
forms: [auto?: true],
params: params
)
end
# phoenix_form = AshPhoenix.FormData.to_form(form, as: "user_profile")
phoenix_form = form
case form.source.action_result do
{:ok, profile} ->
{:noreply,
assign(socket, profile: profile, form: form, phoenix_form: phoenixform, success: true)}
->
{:noreply, assign(socket, form: form, phoenix_form: phoenix_form, success: false)}
end
thats a no - what's
form.source.action_result
?I am. not able to render form at all
application stuck
yes, you need to call
to_form
on the AshPhoenix.Form to make it compatible with Phoenix. I'd recommend reading through the docs at https://hexdocs.pm/ash_phoenix/AshPhoenix.Form.html to see how to work with formsok sure, thank you
I am doing this "phoenix_form = AshPhoenix.FormData.to_form(form, as: "user_profile")" still same issue
ok
my dependency {:ash_phoenix, "~> 2.3"}, why I am not able do import AshPhoenix.FormComponents
because it doesn't exist
where did you get that from?
I am getting this error not able to resolve
again, going to need more information
start from the error, and work backwards. what line of code is it pointing to, in your app's code?
<.input form={@form} field={:email} label="Email" readonly class="w-full px-3 py-2 border rounded bg-gray-100" /> this line, the email coming from ash_authentication user profile
compare that line to other forms in your app - do they do form fields the same way?
ok
I am first time trying with ash phoenix form component, I am not getting clue my complete component as shown below
none of the issues so far have been related to AshPhoenix.Form - they've all been from Phoenix
ok
and this one is going to be around your
input
component, and the data it expects
there will be examples of how to use it in the generated CoreComponents file, presuming you haven't edited the componentlet me start from scratch with
restarting from scratch whenever you have to debug an issue isn't really a feasible strategy
I think you overriden your form here with old form that was not "to form". that's why the error, it's not "to form" form.

🤔 now I see the first line is commented out also. I'm thinking it should be the other way around, or just
phoenix_form = to_form(form, as: "user_profile")
did you try that and it didn't work?to_form()
is definitely necessary