view_widget.xml
This page lists all of the available tags within the view_widget.xml file and how to access them from within the widget
Last updated
Was this helpful?
This page lists all of the available tags within the view_widget.xml file and how to access them from within the widget
Last updated
Was this helpful?
As described before, this file allows the developer to create a form so that it can be displayed as a GUI at the moment of creating the Widget on a dashboard.
The contents of this file are Ubidots-mapped XML-like tags to React elements, so it actually differs from the traditional XML supported tags. Also, view.xml
and view_widget.xml
are implemented differently, so their supported tags are different.
Please check our Custom UI documentation in order to know the available elements and how to use them:
Note that Ubidots native widgets feature two configuration tabs as shown below:
Settings.
Appearance.
The same can be implemented within plugin widget's drawer by using the tabs
element in the view_widget.xml
filie. The following is a valid configuration featuring 3 different tabs: Settings
, Appearance
, Advanced
:
The configuration above renders the following drawer:
The name and number of tabs is not fixed, that is, you can add and name tabs as you require other than settings
and appareance
.
To ensure that the ubidots.getWidget().getSettings()
method returns a structured object where child elements are correctly nested under their respective tabs, element IDs should follow the format:
Tabs within the widget drawer help developers organize user input more effectively, making the interface clearer and more structured. Tabs have 2 attributes:
id: Unique identifier for tab element.
title: This is the text that will be displayed in the drawer to identify the tab.
Within a tab you can place all form elements available in the Custom UI.
Using Parent-Referenced IDs
This method explicitly associates each element with its parent tab. The resulting xmlSettings
object maintains a structured hierarchy, grouping settings under their respective tabs.
Example XML:
Resulting JSON (ubidots.getWidget().getSettings()
):
This structure ensures that settings remain grouped under their corresponding tab.
If element IDs do not reference their parent tab, all elements will be placed at the root of xmlSettings
, making it harder to determine which tab they belong to.
Example XML:
Resulting JSON (ubidots.getWidget().getSettings()
):
In this case, all child elements appear at the root level, losing their association with their parent tab.
Best Practice
To maintain a well-structured configuration it is strongly recommended to follow the parent-tab-id.child-element-id
convention when defining IDs for elements inside tabs.
Ubidots native widgets offer the capability to select the target variables for the widget as well as the widget behavior (static or dynamic):
The same can be achieved by using the addvariable
element in the view_widget.xml
file
For example, in order to replicate the Metric widget's UI shown above, you can use the following view_widget.xml
:
Note that within the addvariable
tag, you can use any of the elements described in the Custom UI documentation.
This element is interpreted such that it displays the whole modal for adding variables. The following are its attributes:
id
Yes
Unique identifier used internally. Don't modify its default value.
maxvariables
Yes
Max number of variables that can be added.
dividername
Yes
Unique identifier used internally. Don't modify its default value.
This element displays a label and a description within a container in order to provide detailed information.
label
Yes
Message displayed when selecting a variable.
description
No
Message displayed below the label message
With this in mind, if you changed the label
attribute from Variable label
to Variables
, such message will be displayed instead.
If your Plugin widget requires information about the variable's aggregation method, you can use a inputcombo
of the dropdown.list
type as shown above, however, for it to work correctly, it is mandatory that the id
attribute has the value aggregationMethod
If your Plugin widget requires a time span for the variable's data, you can use a inputcombo
of the span
type as shown above, however, for it to work correctly, it is mandatory that the id
attribute has the value span
The view_widget.xml
elements can be accessed from within the widget.js script using the input combo id attribute.
For example, suppose your Widget is implementing the following view_widget.xml
file:
You can access all of these data as follows:
Then, the settings
object will be something like:
This object contains on the root level, all the keys corresponding to each of the view_widget.xml
element's id.
For example note that above, it was used two input combo whose ids are device_label
and tittle
correspondingly, also note that those keys are within the settings object. Also note variables
key, this is always a list containing the selected variables.
You can also access the widget's endpoint in the following way: