You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't know, if it is a bug in Alpine or if I missed something in the documentation. As soon as individual x-data elements are surrounded by another x-data element, they behave different.
Below is a simple example:
On init() the button is selected
A getter function selectButtonLabel returns the data-label attribute of the button
Current behavior
As soon as the individual buttons are surrounded with another <div x-data></div> element, the buttons get the label from the last button (Dropdown 3).
Expected behavior
Both examples should behave the same and every button should get it's own data label.
Example:
<h3>Individual Buttons (works as expected)</h3><divx-data="dropdownTest"><button@click="toggle" data-label="Dropdown 1" x-text="selectButtonLabel" class="select" type="button">Dropdown</button></div><divx-data="dropdownTest"><button@click="toggle" data-label="Dropdown 2" x-text="selectButtonLabel" class="select" type="button">Dropdown</button></div><divx-data="dropdownTest"><button@click="toggle" data-label="Dropdown 3" x-text="selectButtonLabel" class="select" type="button">Dropdown</button></div><h3>Surrounded by x-data (behaves different)</h3>
Here, all buttons will get named with "Dropdown 3":
<divx-data><divx-data="dropdownTest"><button@click="toggle" data-label="Dropdown 1" x-text="selectButtonLabel" class="select" type="button">Dropdown</button></div><divx-data="dropdownTest"><button@click="toggle" data-label="Dropdown 2" x-text="selectButtonLabel" class="select" type="button">Dropdown</button></div><divx-data="dropdownTest"><button@click="toggle" data-label="Dropdown 3" x-text="selectButtonLabel" class="select" type="button">Dropdown</button></div></div>
Thank you for your assistance and ideas. I already tested to name the "x-data" attributes different (dropdownTest1, dropdownTest2, etc.), but this has the same effect. In my opinion this should not happen, because every element has it's own instance of the DropdownTest class.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi Everyone
I don't know, if it is a bug in Alpine or if I missed something in the documentation. As soon as individual x-data elements are surrounded by another x-data element, they behave different.
Below is a simple example:
init()the button is selectedselectButtonLabelreturns thedata-labelattribute of the buttonCurrent behavior
As soon as the individual buttons are surrounded with another
<div x-data></div>element, the buttons get the label from the last button (Dropdown 3).Expected behavior
Both examples should behave the same and every button should get it's own data label.
Example:
JavaScript:
Full working example to see the effect:
https://codepen.io/mitosch/pen/zxqbVqO
Thank you for your assistance and ideas. I already tested to name the "x-data" attributes different (dropdownTest1, dropdownTest2, etc.), but this has the same effect. In my opinion this should not happen, because every element has it's own instance of the DropdownTest class.
Beta Was this translation helpful? Give feedback.
All reactions