Javascript reference - Address Autocomplete Widget
AddressFinder.Widget class
This page serves as a reference for the constructor, methods, options, and events available in the Address Autocomplete Widget.
List of configuration options and common code examples can also be found in this folder.
Constructor
| Constructor | Parameter | Description |
|---|---|---|
AddressFinder.Widget() | input:Element, api_key:String, country_code:String, options?:Object | Attaches a new widget to the specified input element. |
Methods
| Method | Parameter | Return value | Description |
|---|---|---|---|
on() | event_name:String, callback:Function | AddressFinder.Widget | Subscribes to a specified event. |
trigger() | event_name:String, arguments… | AddressFinder.Widget | Manually fires a specified event. |
setOption() | option_name:String, value:* | AddressFinder.Widget | Sets an option after the widget has been initialised. |
setCountry() | country_code:String | AddressFinder.Widget | Sets a country after the widget has been initialised. |
getOption() | option_name:String | AddressFinder.Widget | Gets the current value of the specified option. |
addService() | name:String, search_function:Function | AddressFinder.Service | Function to add an additional third-party search. |
disable() | - | AddressFinder.Widget | Disables the Addressfinder widget. The autocomplete function will stop operating until it is re-enabled. |
enable() | - | AddressFinder.Widget | Re-enables a disabled Addressfinder widget. |
Options
| Key | Type | Description |
|---|---|---|
address_params | Object | Additional parameters to filter the address results. Please refer to the API autocomplete documentation for AU, NZ and Int. Defaults to {gnaf: "1"} |
address_metadata_params | Object | Additional parameters to adjust the values returned with address metadata. Please refer to the API documentation for AU, NZ and Int |
base_url | String | The base URL endpoint for API calls and CSS resources. |
canonical | Boolean | Force the selection of the canonical address when an aliased address is selected. Defaults to true |
container | Object | The element that wraps in input field that AddressFinder will use. This is useful when embedding the widget within a scrolling panel. Defaults to document.body |
empty_class | String | CSS class name to be applied to the li element containing the empty_content message. Defaults to af_empty |
empty_content | String | Message to display to users when there are no found addresses or locations. Defaults to No addresses were found. This could be a new address, or you may need to check the spelling. |
footer_class | String | CSS class name to be applied to the li element containing the footer. Defaults to af_footer |
hover_class | String | CSS class name to be applied to the li element of a highlighted result. Defaults to af_hover |
ignore_returns | Boolean | Ignore the use of the enter key when no list item is selected. Defaults to true |
item_class | String | CSS class name to be applied to the li element of a result. Defaults to af_item |
list_class | String | CSS class name to be applied to the ul element containing the results. Defaults to af_list |
location_params | Object | Additional parameters to filter the location results. Defaults to {} |
manual_style | Boolean | If true, the widget will not embed the default stylesheet, allowing a custom stylesheet to be used. (Can only be set when widget is constructed). Defaults to false |
max_results | Integer | Maximum number of results to display. Defaults to 10 |
position | String | Use a different positioning value for the list_class element. When embedding AddressFinder within a fixed position element, using a matching fixed position value will ensure the popup list appears below the input element. Defaults to 'absolute' |
show_addresses | Boolean | Set to false to hide address results. Defaults to true |
show_locations | Boolean | Set to true to return location (Street, suburb, city) results. Defaults to false |
Events
| Events | Callback arguments | Description |
|---|---|---|
"result:select" | selectedAddress:String, metadata:Object | Fired when any result is selected. The metadata value returned depends on the type of address selected and country. |
"address:select" | selectedAddress:String, metadata:Object | Just like "result:select", but only fired when an address is selected. |
"address:select:pre" | selectedAddress:String, metadata:Object | Fired immediately when an address is selected, before an info request for extended data is made. |
"location:select" | selectedLocation:String, metadata:Object | Just like "result:select", but only fired when a location is selected. |
"location:select:pre" | selectedLocation:String, metadata:Object | Fired immediately when an location is selected, before an info request for extended data is made. |
"results:update" | - | Fired when all services have updated their results. |
"results:empty" | - | Fired when there are no results to display. |
AddressFinder.Service class
Constructor
AddressFinder.Service is returned from the AddressFinder.Widget#addService method.
Method
| Method | Parameter | Return value | Description |
|---|---|---|---|
on() | event_name:String, callback:Function | AddressFinder.Service | Subscribes an a specified event. |
trigger() | event_name:String, arguments... | AddressFinder.Service | Manually fires a specified event. |
setOption() | option_name:String, value:* | AddressFinder.Service | Sets an option after the widget has been initialised. |
getOption() | option_name:String | AddressFinder.Service | Gets the current value of the specified option. |
Options
| Key | Type | Description | Default |
|---|---|---|---|
renderer | Function | Allows a function to be defined to format how the result will be displayed. The function will be passed two arguments, the value and the data, and must return a string. | - |
Events
| Events | Callback arguments | Description |
|---|---|---|
"result:select" | selectedAddress:String, metadata:Object | Fired when a result from this service is selected. |