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 Responses

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

belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
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
dotdotdotPaul
Okay, I’m having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I’m sure I’...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30877 112
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 52341 488
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New

We're in Beta

About us Mission Statement