willc0de4food

willc0de4food

Render error message for hidden field

Hello! I have a hidden input and I’m using buttons to set it’s value. The default value for this field is nil. If a user doesn’t select one of the options, I would like to show the error from the changeset beneath the buttons, like with other form fields that have automatic error handling. How can this be done?

I’ve seen references to an error_tag, but such a tag no longer exists as far as I can tell?

Thanks!

Most Liked

msmithstubbs

msmithstubbs

Before Phoenix 1.7 error_tag was a function defined for you in the ErrorHelpers module (source).

Since 1.7 there is a CoreComponents module. If has an <.input /> component that renders an input field with error feedback using <.error />. So you could use that:

<.input field={@form[:some_field]} type="hidden" />

This will generate a hidden input field and the error feedback.

If you’d rather display the error yourself you can just access it directly: @form[:some_field].errors and render it as you like.

The Phoenix Form Bindings guide discusses using phx-feedback attribute for styling and hiding error messages.

Updated: Just noticed LiveView 1.0 will drop support for phx-feedback.

LostKobrakai

LostKobrakai

Not sure how this wouldn’t seem relevant, but if you follow what happens as part of <.input> it would show that it does the following eventually:

<.error :for={msg <- Enum.map(@form[:gender].errors, &translate_error(&1)}><%= msg %></.error>

Where Next?

Popular in Questions Top

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lists...
New
nobody
How to bind a phoenix app to a specific ip address? could not find anything about that, nowhere, unfortunately, but for me this is quite...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; somethi...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New

Other popular topics Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 41539 114
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a &gt; b) do {:ok, "a"} end if (a &lt; b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement