jason.o
Changset.add_error not working inside `before_action` block?
This code is intended to validate a user typed DELETE before deleting their account, but it doesn’t work because add_error isn’t adding the error nor making the changeset valid?: false. Perhaps the issue might be that it’s run inside before_action which was needed so that the validation doesn’t happen until form submission. What’s the right way to accomplish this? Thanks.
change fn changeset, _ ->
Ash.Changeset.before_action(changeset, fn changeset ->
if Ash.Changeset.get_argument(changeset, :confirm_word) == "DELETE" do
changeset
else
changeset
|> Ash.Changeset.add_error(
field: :confirm_word,
message: "Type DELETE to confirm"
)
end
end)
end
Marked As Solved
zachdaniel
Is the example you’re showing a simplified example? Are you sure you’re properly returning the changeset with the error, that kind of thing? I’ve tested it against multiple data layers/resources and it appears to work as expected.
Also Liked
zachdaniel
Very interesting. I think I may know the issue. I’ll have to reproduce it and confirm when I’m home later this evening. If you can open a GH issue on ash core with all of this detail, I should have the issue resolved tonight or tomorrow. Does that work for you?
jason.o
No, it’s not a simplified example. Let me try to create a minimal example that reproduces the issue.
Last Post!
jason.o
Popular in Questions
Other popular topics
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
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










