Ash FrameworkAF
Ash Framework3y ago
7 replies
axdc

Custom validation error not appearing in form

I'm using the .input and .inputs_for components from Phoenix, and I see the normal is required errors in the html when I leave fields blank, but while my custom error shows up in the changeset from IO.inspect I don't see it in the html.
The validation:
defmodule Panacea.Sites.Validations.ValidateHostname do
  use Ash.Resource.Validation
  alias Ash.Error.Changes.InvalidAttribute

  alias Ash.Changeset

  @impl true
  def init(opts), do: {:ok, opts}

  @impl true
  @spec validate(Changeset.t(), Keyword.t()) :: :ok | {:error, term()}
  def validate(changeset, keyword) do
    IO.inspect(changeset)
    IO.inspect(keyword)

    # always return an error because i am trying to see it 
    {:error,
     InvalidAttribute.exception(
       message: "hello i am an error if you cannot see me that is a bigger error"
     )}
  end
end

The resource:
...
  validations do
    validate Panacea.Sites.Validations.ValidateHostname
  end
...

Is there something I'm missing in implementing a validation or could it be something in the form?
Was this page helpful?