Validation issue with v0.5.19-rc.1
totaltrash opened this issue · comments
Describe the bug
Validations are a bit broken - validation occurs, but errors are not appearing on the fields
To Reproduce
Create a resource with:
attribute :note, :string do
allow_nil?(false)
default("HELLO")
end
and a form
AshPhoenix.Form.for_create(Activity, :create,
as: "activity",
api: Projects
)
Open the form, clear the "HELLO" value from the note, validate, validation occurs (error on the form), but no error message on the field. type something in the box, form error goes away, clear it again and error message does appear on the field this time...
Expected behavior
Error appears on the field
** Runtime
- Elixir version
- Erlang version
- OS
- Ash version
- any related extension versions
Additional context
Add any other context about the problem here.
I'm trying to reproduce with a simple test:
describe "validation errors are attached to fields" do
form = Form.for_create(PostWithDefault, :create, api: Api)
form = Form.validate(form, %{"text" => ""})
assert %{errors: [text: {"is required", []}]} = form_for(form, "foo")
assert form.valid? == false
end
I think this should be the reproduction for the first steps, e.g making a form, not touching the default, then setting the attribute to an empty string. This test passes with text as ""
or nil
. Would love to get to the bottom of this, so perhaps you can spot where the test does not accurately reproduce the issue.
I'll push the test up to master
fixed thanks Zach!