Tip - How to find Widget elements for JavaScript
Hi All,
I worked this out a little while ago and thought that I should share it with everyone as it can come in handy when trying to work out how to use JavaScript to control widgets.
The issue that I've faced is trying to work out what all different elements that make up a widget are called. You can see them in the Widget details pane on the right side of the screen when you select one, but it's not really consistent at the back end for naming compared to what I shows in the UI.
There are two ways to see the correct name:
Method 1 - Look in the app.js file
As you create your project, there is an app.js file stored in Projects\<Project_Name>\dist\app. If you open up this file in an editor, you can search for your widget by name and then if you scroll around, you can see all the twx-widget-property definitions.
As an example, if I look for a 2D image widget that I've put into the experience, I can see the following property:
<twx-widget-property name="imgsrc" datatype="resource_url" value="app/resources/Default/vu_seq_play.svg">
If I look at a 3D image widget, the source image property is different (src vs. imgsrc):
<twx-widget-property name="src" datatype="resource_url" value="app/resources/Default/vu_alert1.svg">
This method is very handy as you can see the property name, the datatype (string. boolean, resource_url, etc.) and the value. Just be careful not to make any changes to this file when looking at it.
Method 2 - Use the Preview
Credit to the AR course on IoT University for this one (see here)
Edit the .js file for the views you want to see the widget info for (e.g. Home.js) and add in the following line:
console.log($scope.app)
When you preview the experience, turn on developer tools (Ctrl + Shift + I) and you'll see an Object item in the list that can be expanded. Expand this out and then go into View, <View_Name>: (e.g. Home), wdg: and then you'll see a list of all the widgets in that view with their property values shown. If you expand the widget, it shows the property and value in a much easier to read format than in the app.js file.
Hope you find this useful.
Allan

