Declarations

Widgets in the APS JS SDK can be declared using either Widget Loader, Widget Constructor, or the Declarative Method as explained below.

Widget Loader

You can declare SDK widgets using a JavaScript array. The best way is to use the load method provided by the aps/load module. This method can accept two arguments:

  • A JSON object describing a widget or an array of such objects

  • Optionally, a DOMNode ID or DOMNode itself, where the required widgets will be added to

require(["aps/load", "aps/ready!"],
   function(load){
      load([ "aps/ProgressBar", { value: "35%" } ]);
});

For more details, refer to Widget Loader.

Note

In UX1, the recommended way for a custom view is to define an array of widgets and return it in the init method. The user panel itself will load the defined widgets for the view.

Widget Constructor

You can declare SDK widgets using JavaScript constructors. First, declare the SDK modules that will be used in the view and associate the names of constructors with them.

require(["aps/Button", "aps/ready!"],
   function(Button){
      var btn = new Button({
         id: "example1",
         label: "I am simple button"
      }, "idDiv");
});

For more details, refer to Widget Constructors.

Declarative Method

In old APS packages, you can meet the declaration of widgets directly in a screen’s HTML layout. For example:

require(["dojo/parser", "aps/ready!"],
   function(parser){
      parser.parse();
});
<div dojoType="aps/CheckBox" title="decCheckBox" data-dojo-props="value: 'helloHTML'"></div>

For more details, refer to the Declarative Method.

Warning

The declarative method is not recommended and we recommend you use the aps/load method.

Widget Processing

All the declaration methods are applicable for any widget. To use a widget after it was created using the loader or declaratively, find it by its Widget ID. This may be useful, for example, when updating a view on a certain event.