Could you give me a hint how I could call the "col...
# kvision
j
Could you give me a hint how I could call the "collapse" methods manually? https://getbootstrap.com/docs/4.0/components/collapse/ I don't have that much experience with JS interop. Therefore I'd be glad if anybody could give me a hint how to call these methods on e.g. a div
r
The simplest case:
Copy code
vPanel {
	lateinit var div: Component
	button("Toggle div").onClick {
		div.getElementJQueryD().collapse("toggle")
	}
	div = div(className = "collapse show") {
		+"Lorem ipsum dolor sit amet, consectetur adipiscing elit."
	}
}
👍 1
j
Thanks!
r
With
data-*
attributes:
Copy code
vPanel {
	button("Toggle div") {
		setAttribute("data-toggle", "collapse")
		setAttribute("data-target", "#collapseExample")
	}
	div(className = "collapse show") {
		id = "collapseExample"
		+"Lorem ipsum dolor sit amet, consectetur adipiscing elit."
	}
}
j
"this._$div_18.getElementJQueryD_37() is null"
calling too early?
r
perhaps do you call it from an event handler?
j
Yes. From within "subscribe"
r
so it can be too early
try
div.getElementJQueryD()?.collapse("toggle")
j
probably the problem. Subscribe is evaluated immedately.
r
it should ignore those early calls
j
it seems
Copy code
div.getElementJQueryD()?.let{}
is not supported by Kotlin 😳
probably interpreted as a JS method
make sense somehow
r
You can make very similar effect easily with just simple KVision methods:
Copy code
vPanel {
	lateinit var div: Div
	button("Toggle div").onClick {
		if (div.visible) div.hideAnim() else div.showAnim()
	}
	div = div {
		+"Lorem ipsum dolor sit amet, consectetur adipiscing elit."
	}
}
👍 1
j
I will give it a try!
Works well! Just one difference: Collapse just animates the height. "hideAnim" seems to animate both width and height
I will try slideDown
r
Yep,
slide
methods should be even better