Best Practices for Creating Mashups Using Widgets and Functions
Use the following best practices while creating mashups with widgets.
Add Layout as Top-Level Widget in a Mashup
It is recommended that you add a Layout widget at the top-level of any container even if you add one widget. Adding a top-level Layout widget gives you the flexibility to add an additional row or column to the area as well as a header or footer in future.
Visibility of Widgets on a Mashup
You can manipulate the visibility of ThingWorx widget at runtime using the widget property Visible.
Validating User Input
Use the Validator function to validate the input that the users want to send to a device. These inputs may change the state of the device, operate the device remotely, and so on. It is recommended to check if the user input is valid. You can use one Validator function for each field you want to validate, or one for more fields if they require the same validations.
Validators accept regular expressions (regex) as input, which enables you to check almost any type of content. If the validation returns false, you can display a status message to the user, and reset the input field to the default value.
Mathematical Conversions
Use the Expression function to perform mathematical conversions at runtime. For example, consider a case where the data about a temperature is displayed in degree Celsius (C). You can provide a radio button that enables a user to see the temperature details in Fahrenheit (F). Based on the user selection of the unit of measurement, the Expression function calculates the value of the temperature and displays it.
It is recommended to use the Expression function rather than a server-side custom service for simple calculations.
Was this helpful?