I hit the odd issue when I had a form with hidden input that had name id. It would cause form to be duplicated. Found out it's an known issue with morphdom.
morphdom vs. named fields
results in the surrounding form being duplicated rather than replaced.
This is because if such a field exists within a form, form.id returns that DOM node rather than the form’s id attribute value.
getNodeKey (Function(node)) - Called to get the Node's unique identifier. This is used by morphdom to rearrange elements rather than creating and destroying an element that already exists. This defaults to using the Node‘s id property. (Note that form fields must not have a name corresponding to forms’ DOM properties, e.g. id.)
I think this should be documented in LiveView's documentation.
Yep, the MDN docs for the input name attribute call this out too. It definitely leads to some strange behaviour!
I added a note to the form guide, thanks!
I hit the odd issue when I had a form with hidden input that had name
id
. It would cause form to be duplicated. Found out it's an known issue with morphdom.Related thread https://elixirforum.com/t/i-had-the-weirdest-problem-with-liveviews-change-tracking-when-name-attribute-has-value-id/39008
Here you can see what happens https://burningchrome.com/~fnd/_/19c4516b-8d17-4d8b-b732-7cfdf4ca49e8.html
It's actually documented in morphdom's github repo https://github.com/patrick-steele-idem/morphdom
I think this should be documented in LiveView's documentation.