Module: UWA/Services/ControlParser




<static> UWA.Services.ControlParser.register(klass, type)

Register a control in the parser.

ControlParser.register('AMD/path/to/a/control', 'control-name');
ControlParser.register('AMD/path/to/a/control SubObject.SubSubObject', 'sub-control-name');
ControlParser.register(ControlClass); // name is extracted from the prototype

function factory(dom) {
   if ( === 'whatever') return new WhatEverControl();
ControlParser.register(factory, 'whatever-name');
Name Type Argument Description
klass Class | String | Function

The control definition or location

type String <optional>

The parser type, corresponding to the uwa-control attribute to search for.

<static> UWA.Services.ControlParser.parse(dom, options)

Parse some dom and instantiate corresponding controls.

var element = UWA.createElement('div', {
   html: '<input type="text" uwa-control="uwa-text" />' +
       '<button type="button" uwa-name="myButton" uwa-control="uwa-button">Clickme</button>'
ControlParser.parse(element, {
   onError: function (error) {
       // debug help
   onSuccess: function (controls) {
       controls.myButton.setValue("Click me now!");

Controls instances:

onComplete and onSuccess gets the created controls passed as their first argument. This will be a hash associating the control name with its instance. If the control name ends with [], it will collect all instances with the same name and store it in an array.

All unnamed controls are stored in the lostAndFound property (which is an array). Ie: the default name is lostAndFound[].

The name of an instance is defined by the attribute uwa-name.

Name Type Description
dom HTMLElement

The root element

options Object

A hash with some options

Name Type Argument Description
onComplete Function <optional>

A callback called once, with an array containing the controls instances as first argument and the last error as second argument.

onSuccess Function <optional>

A callback called once if there is no error, with an array containing the controls instances as first argument.

onError <optional>

A callback called for each error, with the error (in general, a string) as first argument.