Replies: 2 comments
-
There's nothing telling Alpine morph that the checkbox is new and the default behaviour is that, if it looks exactly the same, Alpine assumes is not new and preserve states. You can use |
Beta Was this translation helpful? Give feedback.
0 replies
-
I would not expect the new element when morphed to sync like that... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I encountered an issue where the checkbox’s state isn’t properly updated after an HTMX morph swap.
Here’s a demo link to reproduce the issue.
Steps to reproduce:
Expected behavior:
The checkbox should become unchecked as the swapped checkbox is a new element that is unchecked.
Actual behavior:
The checkbox remains checked, even though the swapped HTML is an entirely new, unchecked checkbox.
Findings:
While investigating, I noticed that the plugin “patches” the attributes of the from node with the to node here. However, in the case of checkboxes, the checked state is controlled by a property on the DOM element, not an attribute.
To resolve this, I added 'patchProperties' alongside 'patchAttributes':
Explanation:
Let me know if this behavior is expected or if there’s a better way to handle this scenario!
Beta Was this translation helpful? Give feedback.
All reactions