umbra
Im having a problem here… as the title suggest, my error_tag isnt working, its simply not showing the error message:
new.html.eex
<%= form_for @changeset, Routes.category_path(@conn, :create), fn f -> %>
<label for="category_name" class="form-label">Nome da Categoria</label>
<%= text_input f, :name, class: "form-control", placeholder: "Nome" %>
<%= error_tag f, :name %>
<%= submit "Cadastrar", class: "btn btn-primary my-3" %>
<% end %>
controller
def create(conn, %{"category" => category}) do
case Records.category_create(category) do
{:ok, _inserted_category} ->
conn
|> put_flash(:info, "Categoria criada!")
|> redirect(to: Routes.category_path(conn, :index))
{:error, changeset} ->
conn
|> put_flash(:error, "Erro ao criar categoria!")
|> render("new.html", changeset: changeset)
end
end
context
defdelegate category_changeset(category, params), to: Category, as: :changeset
defdelegate category_create(params), to: Category, as: :create
changeset and repo action
def changeset(%Category{} = category, params \\ %{}) do
category
|> cast(params, [:name])
|> validate_required([:name])
|> validate_length(:name, min: 3, max: 15)
|> validate_format(:name, ~r{\S})
|> unique_constraint(:name)
end
def create(params) do
%Category{}
|> changeset(params)
|> Repo.insert()
end
inspected changeset
Its working properly, the error is there!
[debug] Processing with ConfinWeb.CategoryController.index/2
Parameters: %{}
Pipelines: [:browser]
[debug] QUERY OK source="categories" db=15.0ms idle=407.0ms
SELECT c0."id", c0."name" FROM "categories" AS c0 []
#Ecto.Changeset<
action: :insert,
changes: %{},
errors: [name: {"can't be blank", [validation: :required]}],
data: #Confin.Records.Category<>,
valid?: false
>
HTML generated
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated!
To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead.
Sta...
New
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app?
Looking for hints regarding:
Addi...
New
Hi all, I wanted to ask how the community is dealing with post-release steps.
Today we have Ecto migrations, which make sure that the db...
New
Kia ora,
We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
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
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #hex
- #performance












First 6 of 6 Posts
lleger
Is this in a LiveView? It looks like it because of the “invalid-feedback” class, which is added by LiveView when the user didn’t change the input. In your CSS that class probably has
display: noneor similar. This is to avoid confusing the user by adding errors to fields they haven’t changed.Docs here: Form bindings — Phoenix LiveView v1.2.5
umbra
Its not LiveView
This is supposed to happen only with LV?
lleger
The default
error_tagimplementation adds theinvalid-feedbackclass automatically. See here: phoenix/installer/templates/phx_web/views/error_helpers.ex at a55f4859aa028e7395b5b84ce0481ac4e5efb659 · phoenixframework/phoenix · GitHubIf you’re using that same function (you didn’t paste the code, so I’m not sure) then that class is being added.
Since it’s in the HTML and not showing, it’s possible you have some CSS that’s adding
display: none. The defaultapp.cssPhoenix generates has this (phoenix/installer/templates/phx_assets/app.css at a55f4859aa028e7395b5b84ce0481ac4e5efb659 · phoenixframework/phoenix · GitHub) but that’s probably not activating since it doesn’t also have thephx-no-feedbackclass.Which is what LV is supposed to do, as the linked docs explain. But if this isn’t a LV, then
phx-no-feedbackisn’t getting applied, so not sure. But I’d inspect the element in the browser to see why it’s being hidden.umbra
Ok, I think that I found the problem!
Im using Bootstrap 5, and happens that it uses a class named
invalid-feedbacktoo.Thanks! I dindt knew that Phoenix uses a class with the same name.
curioustolearn
I am having this same issue with bootstrap - no errors are being displayed. I am using Phoenix Liveview. For form fields that have not yet received any input I see both
phx-no-feedbackandinvalid-feedbackclasses. As the fields receive input, thephx-no-feedbackis removed from them. However, theinvalid-feedbackclass remains. Am I not seeing the errors because of this class? How do I make sure that the errors are displayed? I would really appreciate some help on this.Update: I also could not find where Phoenix sets the styling for
phx-no-feedbackandinvalid-feedbackclasses.Thank you!
aywen
This is probably way too late, but in case someone else stumbles across this thread as well.
Possible causes of error tag not showing:
invalid-feedbackclass… you might want to comment it out while debugging to make it easier. (The class will typically be defined in .css file in/assets/css/app.css):nilor :ignore, error will not be shown. (See a note on errors in Phoenix.HTML.Form). If this is the case you can either use# {_reply, changeset} = Changeset.apply_action(changeset, :insert)or change the action field manually e.g.{:noreply, assign(socket, changeset: %{changeset | action: :insert})}.`
Also, I’ve found a related post on the topic.