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
Open up webdeveloper tools (I use Google Chrome), go to Console tab and execute: $("#collapse .accordion-body:last").collapse("show");
Result: The last accordion opens, but the first isn't closed.
The problem (briefly):
The third accordion doesn't have parent option set, because we didn't provide it.
The workaround solution:
Start the third accordion with parent option set, and after that try to show() it. Note, that hide() and toggle() also triggers this bug.
The proper solution:
Collapse constructor should look for parent setting (and all other too) in data- attributes of the $() element, as a fallback. If user doesn't provide these options, he obviously wants the Collapse to read those from data- attributes.
The cry story:
Wasted a couple of hours, why the accordion didn't work after show(). It's super counter intuitive, that the options aren't read from data- attributes, when you start the Collapse manual way. I suppose all other plugins inherit the same behaviour (starting by data- attributes reads options from these attributes, where starting manual way don't).
Kind regards
-------- Edit
It's funny when you notice your own mistake only after you cry about it.
Of course accordion-body doesn't have data- attributes to read from, so the The proper solution isn't quite working. But the problem remains. How do we mix the auto data- usage with the manual usage. I.e. how to achieve such a workflow:
Start the accordion/collapse through data- attributes.
open(), hide(), toggle(), whatever() the accordion manually (occasionally) later on.
?
-------- Edit
Ok, it was quite easy: $("#collapse .accordion-body:last").collapse({parent: "#accordion2"}, "show");. But, can you see the notobviousleness of this solution? If I wanna show() an accordion, I don't wanna think to which parent it belongs, since I've already provided the information in the accordion-toggle. I just want the damn thing to show itself properly ;p. Also note the information duplication in this solution, which simply leads to maintenance hell in the future.
The text was updated successfully, but these errors were encountered:
Except such a click would fire many more things in my case. I had to solve this issue by dropping the parent argument from collapse() and manually closing all the other accordions.
Wouldn't it be just simpler, if we could define at the parent element a data- attribute, that tells, that all the accordion-groups below the parent node are part of one accordion, that allows only one accordion-group to be opened at any time? Collapse plugin could search for the immediate parent of current accordion-group (in which the collapsable accordion-body resides) and check, whether it has the data- atrribute. By the way we could get rid of code duplication in every accordion-toggle's data-parent attribute,
Hello,
straight to the point:
To reproduce:
$("#collapse .accordion-body:last").collapse("show");
The problem (briefly):
The third accordion doesn't have
parent
option set, because we didn't provide it.The workaround solution:
Start the third accordion with parent option set, and after that try to
show()
it. Note, thathide()
andtoggle()
also triggers this bug.The proper solution:
Collapse constructor should look for
parent
setting (and all other too) indata-
attributes of the$()
element, as a fallback. If user doesn't provide these options, he obviously wants the Collapse to read those fromdata-
attributes.The cry story:
Wasted a couple of hours, why the accordion didn't work after
show()
. It's super counter intuitive, that theoptions
aren't read fromdata-
attributes, when you start the Collapse manual way. I suppose all other plugins inherit the same behaviour (starting bydata-
attributes readsoptions
from these attributes, where starting manual way don't).Kind regards
-------- Edit
It's funny when you notice your own mistake only after you cry about it.
Of course
accordion-body
doesn't havedata-
attributes to read from, so theThe proper solution
isn't quite working. But the problem remains. How do we mix the autodata-
usage with the manual usage. I.e. how to achieve such a workflow:data-
attributes.open()
,hide()
,toggle()
,whatever()
the accordion manually (occasionally) later on.?
-------- Edit
Ok, it was quite easy:
$("#collapse .accordion-body:last").collapse({parent: "#accordion2"}, "show");
. But, can you see the notobviousleness of this solution? If I wannashow()
an accordion, I don't wanna think to whichparent
it belongs, since I've already provided the information in theaccordion-toggle
. I just want the damn thing to show itself properly ;p. Also note the information duplication in this solution, which simply leads to maintenance hell in the future.The text was updated successfully, but these errors were encountered: