coen.bakker

coen.bakker

Quick question.

I have been reading up on using forms in LiveView. I come across the error_tag/2 function often (for example in this 2022 article by Sophie DeBenedetto) but in the latest official documentation I cannot find any mention of it.

Is error_tag/2 deprecated?

Showing Posts 1 to 9

josevalim

josevalim

Creator of Elixir

error_tag was always part of your app. So you can just add something that does the same to your app. IIRC it was just an error string wrapped in a span tag.

coen.bakker

coen.bakker OP

Yes, I believe it used to be injected into any project scaffolded with mix new, inside ErrorHelpers.ex. I reckon that it has been removed from the mix new boilerplate code, in favour of the error/1 function component that’s part of the core components? Which also basically also just a wrapper.

josevalim

josevalim

Creator of Elixir

Yes, that tracks!

smathy

smathy

It’d be nice if all bloggers led off with the versions of stack they’re using :slight_smile:

The 1.7 release at the start of 2023 was a big change: components and verified routes involved a lot of changes to the view templates. So you’re going to need to account for that when reading any blog from 2022 or earlier. The official changelog is a great source of lots of information about those changes.

coen.bakker

coen.bakker OP

Awfully off topic, but would you ever say “yes” to being on Lex Fridman’s podcast?

N.B., I have no ties to him. But I like the idea of being able to tune into a long form, uncut interview.

josevalim

josevalim

Creator of Elixir

Sure! My arm appreciates as many breaks as possible, especially long ones. :slight_smile:

silverdr

silverdr

It was defined as follows:

	use Phoenix.HTML

	@doc """
	Generates tag for inlined form input errors.
	"""
	def error_tag(form, field) do
		Enum.map(
			Keyword.get_values(form.errors, field), fn error ->
				content_tag(
					:span,
					translate_error(error),
					class: "invalid-feedback",
					phx_feedback_for: input_name(form, field)
				)
			end
		)
	end

So… I now have error_tag/2 all over my application. Wondering if I could easily change this to use the latest approach, including translations and w/o replacing all those error_tags scattered across large number of files/forms. How would you experts do it? Any caveats/gotchas to expect? Yes, I know there’s the “shim”, utilising which should do the trick I presume, but I think of taking a step towards the LiveView 1.0.x approach, while still w/o replacing all those occurrences.

LostKobrakai

LostKobrakai

Replacing this shouldn’t be much of a problem. Most functions in Phoenix.HTML (including content_tag) return data for which the Phoenix.HTML.Safe protocol is implemented. The data you get from ~H sigils also has a implementation of that protocol. This error_tag function returns a list of safe data, but the protocol for implementation for lists just iterates nested safe data, so returning the results of a single ~H should generally also be fine.

You might have places in your codebase, which depend on the return value being a list or even dig deeper into the results, but I’d argue those would be worth fixing and I wouldn’t expect many of such in a codebase.

silverdr

silverdr

I don’t recall ever using it in a deeply unusual way. Differences might be mostly (if not only) in the placement I believe. Either right next/under the corresponding input or grouped into errors summary boxes. Shall have a stab at replacing the implementation then and see how it goes, thank you.

— All posts loaded —

Where Next? Top

Trending in Questions Top

water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New

Other Trending Topics Top

KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews