Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested form errors for argument attribute #119

Merged

Conversation

rgraff
Copy link
Contributor

@rgraff rgraff commented Nov 27, 2023

This may be an X/Y problem, but what I'm trying to do is have an action with an argument that is an embedded resource. The argument resource itself may be valid, but in the context of the parent it is invalid, so the parent creates an add an error with the path to the arguments attribute. That error is not being propagated to the nested form of the argument.

This is a test to reproduce the problem.

Discussed here:
https://elixirforum.com/t/setting-path-on-an-error/59857/3

Contributor checklist

  • Bug fixes include regression tests
  • Features include unit/acceptance tests

@zachdaniel
Copy link
Contributor

Thanks for the PR! Going to merge and poke around a bit.

@zachdaniel zachdaniel merged commit a098a83 into ash-project:main Nov 28, 2023
@zachdaniel
Copy link
Contributor

Alright, so I've addressed some issues with the underlying logic, but the main thing you'll want to do here is not rely on the underlying structure for extracting errors. Use AshPhoenix.Form.errors(form) to get what you need. You can pass a path: AshPhoenix.Form.errors(form, for_path: [:nested_form]) for example, or AshPhoenix.Form.errors(form, for_path: [:all]) to get a map of all paths to errors.

@rgraff
Copy link
Contributor Author

rgraff commented Nov 28, 2023

@zachdaniel I'll try it out. I'm just using the phoenix core components and inputs_for, so I'm not sure how it accesses the errors on the nested form.

@zachdaniel
Copy link
Contributor

Oh, interesting...yeah lets see if my changes helped.

@rgraff
Copy link
Contributor Author

rgraff commented Nov 28, 2023

I can get the errors from AshPhoenix.Form.errors(form, for_path: [:nested_form]) but those errors don't appear on the nested form that comes out of PhoenixComponent.inputs_for/1

Important to note is that errors added by constraints on an embedded resource used as an argument do work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants