Harmony RightAddress JavaScript UI client

The UI client is an even easier way of configuring a web page to use Harmony RightAddress.

The UI client uses jQuery and jQuery UI to create 'auto-complete' fields that invoke the Harmony RightAddress service methods.

Pre-requisites

Before you can use the Harmony RightAddress client, you must make sure you have:

  • An active Harmony RightAddress account
  • A Harmony RightAddress username and password for your domain

Getting the client

The versions of the JavaScript UI client can be downloaded using the following links:

Configuring the client dependencies

The UI client is dependent on the following JavaScript libraries:

These dependencies should be included on the web page before the UI client. In the following example, the three JavaScript files have been downloaded to the 'scripts' folder in the root of the website:


    <!-- Include the JavaScript dependencies -->
    <script src="/scripts/jquery-1.9.0.min.js" type="text/javascript"></script>
    <script src="/scripts/jquery-ui-1.10.3.min.js" type="text/javascript"></script>
    <script src="/scripts/harmony-1.7.0.min.js" type="text/javascript"></script>

    <!-- Include the Harmony RightAddress JavaScript UI client -->
    <script src="/scripts/harmony-ui-1.7.0.min.js" type="text/javascript"></script>

For the jQuery UI styles to work correctly, the stylesheets should also be included on the web page.


    <!-- Include the jQuery UI stylesheets -->
    <link href="/styles/css/jquery-ui-1.10.1.custom.min.css"
            rel="stylesheet" type="text/css"/>
    <link href="/styles/ui-lightness/jquery-ui-1.10.3.custom.min.css"
            rel="stylesheet" type="text/css"/>

Initialising the client

Before making service requests, the client must be initialised. This is done by invoking the init method on the global Harmony object:


    Harmony.init({String} username, {String} password, {String} locale);

This method must be called before any other methods are invoked on the Harmony object.


    <script type="text/javascript">

        Harmony.init("webUser", "password", Harmony.AUSTRALIA);

    </script>

Creating a single-line address lookup

Once the Harmony RightAddress client has been initialised, lookup fields can be created using the global Harmony.UI object.

The following example creates an AUPAF single-line address lookup on a text input with the id 'address':


    <script type="text/javascript">

        Harmony.init("webUser", "password", Harmony.AUSTRALIA);

        Harmony.UI.addressLookup($("#address"), Harmony.AUPAF);

    </script>

The following example creates an AUPAF single-line address lookup on a text input with the id 'address' and id 'state' to filter addresses with a certain state:


    <script type="text/javascript">

        Harmony.init("webUser", "password", Harmony.AUSTRALIA);

        Harmony.UI.addressLookup($("#address"), Harmony.AUPAF, undefined, $("#state"));

    </script>

The following example creates two AUPAF single-line address lookups on a text input with the id 'address' and 'address1':


    <script type="text/javascript">

        Harmony.init("webUser", "password", Harmony.AUSTRALIA);

        Harmony.UI.addressLookup($("#address"), Harmony.AUPAF);
        Harmony.UI.addressLookup($("#address1"), Harmony.AUPAF, undefined, null, 1);

    </script>

Creating a component address lookup

Multiple lookup components can be defined on a single web page and they are automatically linked to the other components on the same page.

For example, if a postcode lookup and locality lookup are defined, selecting a postcode from the lookup will automatically populate the locality field as well (and vice versa).

The following example creates three lookup components for GNAF: a postcode lookup, a locality lookup and a street lookup:


    <script type="text/javascript">

        Harmony.init("webUser", "password", Harmony.AUSTRALIA);

        Harmony.UI.postcodeLookup($("#postcode"), Harmony.AUPAF);
        Harmony.UI.localityLookup($("#locality"), Harmony.AUPAF);
        Harmony.UI.streetLookup($("#street"), Harmony.AUPAF);

    </script>

A user will be able to use the above example to find a street by drilling down through the postcode and locality values.

Specifying output fields

As well as performing address lookups, the UI client can output additional fields from the lookups performed. This is done by adding fields using the global Harmony.UI object.

The following example configures a single-line address lookup which then outputs the component parts of the resulting address to separate fields on the page:


    <script type="text/javascript">

        Harmony.init("webUser", "password", Harmony.AUSTRALIA);

        // Configure the address lookup.
        Harmony.UI.addressLookup($("#address"), Harmony.AUPAF);

        // Configure the output fields.
        Harmony.UI.addField(Harmony.POSTCODE, $("#postcode"));
        Harmony.UI.addField(Harmony.LOCALITY, $("#locality"));
        Harmony.UI.addField(Harmony.STREET, $("#street"));

    </script>

The following example configures two single-line address lookups which then outputs the component parts of the resulting address to separate fields on the page:


    <script type="text/javascript">

        Harmony.init("webUser", "password", Harmony.AUSTRALIA);

        // Configure the address lookup.
        Harmony.UI.addressLookup($("#address"), Harmony.AUPAF);
        Harmony.UI.addressLookup($("#address1"), Harmony.AUPAF, undefined, null, 1);

        // Configure the output fields.
        Harmony.UI.addField(Harmony.POSTCODE, $("#postcode"));
        Harmony.UI.addField(Harmony.LOCALITY, $("#locality"));
        Harmony.UI.addField(Harmony.STREET, $("#street"));

        Harmony.UI.addField(Harmony.POSTCODE, $("#postcode1"), 1);
        Harmony.UI.addField(Harmony.LOCALITY, $("#locality1"), 1);
        Harmony.UI.addField(Harmony.STREET, $("#street1"), 1);

    </script>

When an address is selected from the lookup, the postcode, locality and street fields will automatically be populated with the corresponding values from the selected address.

Additional information

See the Harmony RightAddress JavaScript UI client API documentation for details on configuring the other lookup components.