I tried to add a change event to the color picker. It doesn’t work, and I don’t understand why.
In the custom html:
<input type = 'color' id = "choosecolor" onchange="color_changed_event()">
<script>
function color_changed_event() {
anvil.call(this,"my_change_func", "color changed")
}
</script>
Inserting window.print() in ‘color_changed_event’ confirms that this is actually called. But I never get to my python method in the code of the custom html form:
Removing () or inserting (this) in onchange="color_changed_event()" did not solve it, but helped me find out that I had to use a specific DOM element instead of “this”:
function color_changed_event() {
var x = document.getElementById("choosecolor");
anvil.call(x,"my_change_func", "color changed")
/# didn't work: anvil.call(this,"my_change_func", "color changed") /#
}
But I much preferred @stucork’s solution of having one line in the custom html and the rest in python code. This is how I will do things from now on. Thanks for educating me!
I updated the app with @stucork’s solution, and kept the other in there as well for reference.