Nested form with filtered subform elements
Let's say there is a nested form with Tweet as the main and Comment as the sub. The requirement is to only show and make editable the comments entered by the current user in the subform. I'm hoping to accomplish this without using CSS tricks of hiding other users' comments.
By loading filtered records into the form using the code below, I was able to make the form look like what I want, but when I submit the form, comments previously made by other users (apparently, filtered out from the form) seem to be removed. Is this the expected behavior of a nested form? Is there a relatively easy way to make it save the change without removing other users' comments?
7 Replies
I'm guessing one way to do this is by defining a clever
create/update action
to handle the comment_form, but wanted to ask here first, in case I'm missing something easier.🤔 there are ways to do this, but it might be a bit complex no matter how you cut it.
What I would suggest is essentially "rolling your own" by using the
ignore?: true
option to manage_relationship
What that does is communicate to things like AshPhoenix.Form
that you manage that relationship in a similar way w/ similar semantics, but you'll handle the inputs yourself
Then:
Thank you!!
Tried this code for changing attribute of the form input manually with the value from the changeset attribute. When the form is validated the first inspect message is printed, but neither message is printed when the form is submitted, which leads me to believe this update action isn't being triggered upon form submission. What could I be missing?
ignore? true
was added to the update
action of Tweet resource. like this.
Here is the form definition in the mount function of the liveview.
could you have a different error happening somewhere? The before action hooks are only called on valid changesets.
The fact that the inspect message in the update action doesn't print makes me think that something is off in the way I trigger the action when the form is submitted.
Oh, thats not how that works really
that
update
code block is evaluated once at compile time
so you'll never see thatmy bad.. yeah, I shouldn't have expected the inspect line in the update action to print.