Declarations

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

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:

  • 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. Preliminary, 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 Declarative Method.

Warning

The declarative method is not recommended and wherever possible we recommend you to 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, in case of updating a view when a certain event occurs.