Replies: 2 comments 8 replies
-
You can do it with oob swap, just inject a boolean variable in your template fragment, like Edit : |
Beta Was this translation helpful? Give feedback.
-
Take 2: If you are listening for a custom event instead of using OOB, you can achieve what you want:
All you have to do in the back to trigger the list refresh now, is to add a response header: Here, the little problem about being efficient, is that you are building the all html page every time and using
|
Beta Was this translation helpful? Give feedback.
-
Hi,
summary of problem:
is there way that when I am returning error (oob) I can prevent target from being swapped and instead oob only act ? I have tried hx-preserve setting it to target but does not help.
I have read https://htmx.org/examples/update-other-content/ but it is not what I intend. read on for details.
I am showing at top a form and at bottom a list. Form allows to add items to list. On success of addition in server db I revert with list as partial and using htmx target I am able to update the html fine.
issue is when there is validation error and I revert back with oob with just form having errors. since I want to get efficient I return just form with errors under its fields and it is replacing form fine but since there is no response for target the list is getting removed. Thus now with form situation is I am unable to submit since target got removed.
here are my ui html/partials. Please suggest if oob I am not using correctly or do I need to add list in oob then I feel its defeating my intention to be efficient.
here is gameformoob.html returned when form validation fails:
here is dashboard.html
here is gameform.html note there is no oob attribute.
here is gamelist.html
one more thing noticed is if response is not 200 ok then htmx does not do any swapping. It would have been better if it did oob swapping only then above issue probably I could have solved.
Beta Was this translation helpful? Give feedback.
All reactions