I am building a Ktor application which should include a drop down menu. In this application I do respond to get requests from a ktor server with HTML, using ApplicationCall.respondHtmlTemplate.
I have a list of strings which should serve as the available options for users.
I can easily add the strings to the drop down menu by creating an option for each string.
fun DIV.renderDropdown() {
label() {
select() {
availableVersions.forEach {
v ->
option("",v)
}
}
}
}
Somewhere else in my code I have a global variable which I want to change, whenever the selection in my dropdown menu is changed.
However I did not find any information whether I can just add a listener to the option which then sets my variable, or how you would something with the same effect here.
Ideally I would love to have something like
var o = option("", v)
o.addOnSelectionChangeListener({
globalVariable = o.getSelectedItem()
}
How can you achieve something like this in ktor/kotlinx?