Not understanding how to use setValue control for a Toggle
I am having difficulties understanding how to set a toggle as true or false from a Python script. I was trying to have it be tied to another component's (lets call it x) result when I hit a button but it only reevaluates the toggle when the result of x has changed, not anytime that it runs or the button is pressed.
So I started to learn about the setValue control for toggles as a possible solution for this but am unsure how to reference that control and everything I need to import to make this work. Do I have to use javascript instead of Python? If not what besides "import setValue from windmill" should I have imported?
i see that this is the proper syntax for it:
setValue(id: string, value: any)
but the "value" and "any" part is a bit vague. So for example to set a toggle to false would i type the follwoing?
--assuming toggle id is 'a'
import setValue from windmill
setValue('a', defaultValueEval(False)
bc when I do I get the following error import bin, browser, server, conf, tools, sys
ModuleNotFoundError: No module named 'browser
'
Do I really need to import all of those as well to use the setValue control?
Any help would be appreciated. If you need anymore information let me know.2 Replies
you have to use javascript which is a frontend script which means it get executed in the browser and can control the dom
to do that from a python script, you may have that frontend script be a "Transformer" of a python script, being executed after it and having easy access to the result
Thanks for the prompt reply. I will take a look and try to figure it out.
I got it figured out. I was just able to use the setValue function in the Transformer like you said. Thank you!