When working with Text controls in Canvas app, one common use case we often encounter is setting the value of the text in the control based on some event that occurred on a different control.
This can be easily accomplished by using one of the below approaches
- Set : Use the Set function to update a global variable that is being referenced on the Text control. The same global variable can be accessed across multiple screens.
- UpdateContext: Similar approach as the Set function but instead of a global variable we will be using a context variable which has the scope set to the current screen and will not be accessible in other screens.
We configured our DropDown control to use the Items property and the OnChange event as shown below.
The text input control uses the variable as below. So every time the drop down selection changes the global variable selectedCountry is updated and the value is reflected on the text control.
We can see global variable 'selectedCountry' by clicking File->Variables
In the above example if we update the OnChange event as shown below leaving everything else the same, our text control would work the same way as before but the variable selectedCountry is no longer a global variable but instead a context variable.
We can see the same being reflected under the variables
The same approach could be applied on any of the Text controls available in Canvas app. In the example above we used a drop down control but you can use it across similar events on different input controls like Button, List box etc.