The client library acts as an extension of Harmony RightAddress JavaScript client. This is a lightweight vanilla JavaScript for auto-complete using the current Address lookup methods.
Please refer to the Code snippet section to copy and paste to your web page.
For JavaScript wrapper for auto-complete with jQuery and jQuery UI, please refer to JavaScript UI client API.
| Name | Description | Since |
|---|---|---|
| HarmonyJS.addField | Adds a new field specifying the field name (e.g. Harmony.POSTCODE, Harmony.LOCALITY, etc)
or the attribute name (e.g. "attributes.Line1", "attributes.Latitude", etc),
and the input element. |
2.0.0 |
| HarmonyJS.addressLookup | Single-line address lookup on the supplied input element. |
2.0.0 |
Adds a new field specifying the field name (e.g. Harmony.POSTCODE, Harmony.LOCALITY, etc)
or the attribute name (e.g. "attributes.Line1", "attributes.Latitude", etc),
and the input element.
Harmony.POSTCODE) or attribute (e.g. "attributes.Line1")
to be added.
input element to be assigned to the field
(e.g. document.getElementById("postcodeField")).
addressLookup.
The following example assigns the Harmony.LOCALITY field to the input element with
localityField ID and the "attributes.Latitude" attribute to the input element with
latitudeField ID:
// Perform the assignment using standard JavaScript on single address lookup.
HarmonyJS.addField(Harmony.LOCALITY, document.getElementById("localityField"));
HarmonyJS.addField("attributes.Latitude", document.getElementById("latitudeField"));
// Perform the assignment using standard JavaScript on the second set address lookup.
HarmonyJS.addField(Harmony.LOCALITY, document.getElementById("localityField"), 1);
HarmonyJS.addField("attributes.Latitude", document.getElementById("latitudeField"), 1);
Creates single-line address lookup with the current Address lookup APIs
on the supplied input and country elements.
It returns the response from find service and
the callback is available via onSelect option.
For retrieve service,
the response is available via ui.onRetrieveItem and the callback is available via
onRetrieve option. For
internationalGeocode service,
if getIntlGeocode options is enabled, the response is available via ui.onIntlGeocodeItem
and the callback is available via onIntlGeocode option.
input address element to create the lookup for
(e.g. document.getElementById("address")).
Harmony.AUSTRALIA for Australia)
or Object in input or select Country element
(e.g. document.getElementById("country")).
Harmony.AUPAF for Australia) or Object in
input or select Source of Truth element
(e.g. document.getElementById("sourceOfTruth")).
getIntlGeocode true/false to enable international geocode call for the selected address,
default is false. And callback functions e.g. onRetrieve and onIntlGeocode
in below sample).
The following example creates a single-line address lookup (use AUPAF for Australian addresses)
on the input element with ID singleLineAddress and country and customized opts:
let opts = {
// min 3 chars to trigger the lookup
minLength: 3,
//autocomplete function will only be called once within the specified time frame (ms)
delay: 500,
// enable Harmony.International.getGeocode for non-AU/NZ countries when address selected.
getIntlGeocode: true,
//Override onSelect function if applicable. It is Optional
onSelect: function (ui) {
console.log('address selected: ' + JSON.stringify(ui));
},
//Override onIntlGeocode function if applicable. It is Optional
//e.g. get ui.onIntlGeocodeItem object for address payload after onIntlGeocode call.
onIntlGeocode: function (ui) {
console.log('geocode address selected: ' + JSON.stringify(ui.onIntlGeocodeItem));
},
//Override onRetrieve function if applicable. It is Optional
//e.g. get ui.onRetrieveItem object for address payload after onRetrieve call.
onRetrieve: function (ui) {
console.log('onRetrieve address selected: ' + JSON.stringify(ui.onRetrieveItem));
}
};
let input = document.getElementById("addressField");
let country = document.getElementById("countryField");
Harmony.useFeatureOptions({ "exposeAttributes": 0, "groupAddresses": 1 });
HarmonyJS.addressLookup(input, country, null, opts);