Error_tag not showing

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
screenshot_20210721_175907

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: none or similar. This is to avoid confusing the user by adding errors to fields they haven’t changed.

Docs here: Form bindings — Phoenix LiveView v0.15.7

Its not LiveView :grimacing:
This is supposed to happen only with LV?

The default error_tag implementation adds the invalid-feedback class automatically. See here: phoenix/error_helpers.ex at a55f4859aa028e7395b5b84ce0481ac4e5efb659 · phoenixframework/phoenix · GitHub

If 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 default app.css Phoenix generates has this (phoenix/app.css at a55f4859aa028e7395b5b84ce0481ac4e5efb659 · phoenixframework/phoenix · GitHub) but that’s probably not activating since it doesn’t also have the phx-no-feedback class.

Which is what LV is supposed to do, as the linked docs explain. But if this isn’t a LV, then phx-no-feedback isn’t getting applied, so not sure. But I’d inspect the element in the browser to see why it’s being hidden.

Ok, I think that I found the problem!
Im using Bootstrap 5, and happens that it uses a class named invalid-feedback too.

Thanks! I dindt knew that Phoenix uses a class with the same name.