-
Notifications
You must be signed in to change notification settings - Fork 220
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
Form does not display errors for nested embeds while using :let
#448
Comments
Errors are only shown after you attempt to insert/update the changeset. You can try calling |
The nested changesets do have an action ( The example code does set an action using the Regarding The problem is, that the validation errors show for the nested embeds, when Looking at the documentation for I am also aware that the documentation states that using the let binding is discouraged because "LiveView can better optimize your code if you access the form fields using Of course there is a "work-around" (as just using the assign also works), and it is by no means a huge problem, but I thought it would make more sense to report it nevertheless. |
Everything works for me if I mark the action from the parent form as well. Since the actions cascade, if anything in the tree is not validated, then it disables the rest. |
This might be the same as phoenixframework/phoenix_live_view#3493? |
How do you "mark the action from the parent form"? I am really wondering what I am doing wrong in the example I gave. It is puzzling that the field using the value from The only difference between these two fields is that The data the fields receive seems to be quite identical as well Also the generated HTML is the same, but of course for one field it does not include the validation errors. I find it even stranger that my example does seem to work over here but doesn't on your side. I will try to have a look into the code of And I just saw @SteffenDE reacting too. I will have a look! |
Updating the example project's mix.ex to use So the fix that was implemented to resolve phoenixframework/phoenix_live_view#3493 resolves the issue I encountered a while back. Good to know. When is this slated for release by the way? |
Chris does LiveView releases, so I don’t know exactly. My educated guess would be in the next two weeks. And I wanted to say sorry for letting this sit here so long - please just ping us if you feel like issues might have been forgotten. Sometimes they indeed have. |
In my case, it worked if I assigned an action to the parent changeset by doing |
Thank you for fixing it and thank you for the sorry. No problem. Sometimes I feel a bit torn between trying to not be obnoxious end indeed trying to not be forgotten 😆
@josevalim I at least would want both cases to work consistently no matter whether I use Anyway. Keep up the good work! 👏🏻 |
When using nested ecto embeds in a live view through
form
andinputs_for
, while simultaneously using the:let
binding, errors for the nested embed no longer show up in the browser.I don't know if that is to be expected or if this is a symptom of a problem with the let binding or the form component for example.
I came across this problem while fiddling around a bit with the example code for issue phoenixframework/phoenix#5901.
For demonstration purposes, I created another example repo which can be used to reproduce this specific issue.
The problem
The problem basically comes down to the following:
In the screenshot above, there are 3 embeds visible in the form, all of them have errors in the
name
fields, but only the first and the third embed show the error.I did the same to all fields, clicked inside and typed another letter to try to trigger the error display.
Below the fields, I printed the form struct for reference where the errors can be seen.
The trigger
The problem is triggered when using the
form
,inputs_for
, andinput
like this:The
:let
is used on the form to bind the form tof
, which is then used to provide the field toinputs_for
and somewhere there seems to be the culprit.At first glance, there does not seem to be a problem with
inputs_for
's behavior. I added a more deeply nested example to the example repo (using the@form
assign directly instead off
for the first level), and nestinginputs_for
twice, while binding the form struct does seem to work there.How to reproduce
As mentioned, there is an example repository that can be used to reproduce this problem. There, I bootstrapped a new phoenix application and added the example liveview in hello/lib/hello_web/live/form_live.ex which includes the schema and the template.
The text was updated successfully, but these errors were encountered: