Greg Steckman
07/18/2021, 8:23 PMGreg Steckman
07/18/2021, 8:24 PMhere
, that sets whether the checkbox is checked by default (when the page loads).Greg Steckman
07/18/2021, 8:26 PMfun main() {
renderComposable(rootElementId = "root") {
var original by remember { mutableStateOf(false) }
Div {
Label(forId = "original") {
Text("Original")
}
CheckboxInput(checked = original) {
id("original")
onInput {
original = it.value
}
}
}
Div {
Label(forId = "copy") {
Text("Copy")
}
CheckboxInput(checked = original) {
id("copy")
}
}
}
}
Initially, if you check the Original checkbox, the Copy checkbox follows. However if you check the Copy checkbox, it will no longer check/uncheck itself according to the value set on the checked attribute.Greg Steckman
07/18/2021, 8:31 PMGreg Steckman
07/18/2021, 8:39 PMhfhbd
07/19/2021, 10:56 AMGreg Steckman
07/19/2021, 2:37 PMOleksandr Karpovich [JB]
07/19/2021, 4:29 PMonInput {
original = it.value
}
to the Copy checkbox?
Didn't it work as well?Greg Steckman
07/20/2021, 1:34 AMGreg Steckman
07/20/2021, 1:54 AMfun HtmlCheckBoxTest(){
var checked = false
val checkBox1 = document.body?.appendElement("Input"){
setAttribute("type", "checkbox")
} as HTMLInputElement
val checkBox2 = document.body?.appendElement("Input"){
setAttribute("type", "checkbox")
} as HTMLInputElement
checkBox1.checked = checked
checkBox2.checked = checked
checkBox1.oninput = {
checked = (it.target as HTMLInputElement).checked
checkBox2.checked = checked
true
}
}
The variable checked is actually not even needed in this example. The point is to show how to programmatically change the checked state of the checkbox - using the checked property of the element, not the checked attribute.