Change the value of the Toggle later

I want to change the value of the Toggle later.

The code is to read the values from the electronic medical record and if Hypertension is on the patient's Problem List, the Hypertension toggle for the main disease will be set to Yes.

The problem is that I cannot change it later on the snippet. I would like to be able to manually toggle the snippet on and off as well, since the chart entries can be incorrect.

{current_text={site: text; selector=textarea}}
{Hypertension=testregex(current_text, "(#|#|♯)\\s*Hypertension")}
Main_Disease:{formtoggle: name=Hypertension; default=no}{endformtoggle}
1 Like

Hi Naritatsu,

You can try setting the default directly rather than using a form variable set with a formula. A formula creates a persistent value binding whereas the default is set once.

For instance, try something like this:

Main_Disease: {formtoggle: name=Hypertension; default={=testregex({site: text; selector=textarea}, "(#|#|♯)\s*Hypertension")}}{endformtoggle}

Also, we're currently developing a feature that lets you run a formula just once instead of creating a persistent binding. It sounds like it could be a perfect fit for your needs once it's released!


Well, that's a good lesson for me.
Thank you very much.

@scott How can we change the initial value in the same way in a text field? I have applied the toggle command but it does not work.

{age=extractregex({site: text; selector=.names-age},"(..)y.o.")}
Age:{formtext: name=age; default=age; cols=2}y.o.

{form} commands cannot depend on form variables for their default values. So your use of age as the default won't work (you would also need default={=age} not default=age).

You can address this by using the formula as the default instead of using a variable. So here you would want something like:

default={=extractregex({site: text; selector=.names-age},"(..)y.o.")}

Does that help?

Thank you very much for your help. It works.