Hook into the Autoaddress jQuery Plugin Events

The Autoaddress plugin is event driven, and we have provided the opportunity for you to hook into these events and add your own logic with custom callback functions. These events range from when the plugin is initialized all the way to the end when your address has been found.

We also pass data back in key events so you can grab this data and perform custom actions to suit your own needs.

See below for details on when these events are triggered and how you can access them.


How to access a callback event

<script type="text/javascript"> 
$("#myDiv").AutoAddress({ 
   key : "YOUR_KEY",
   //Search Lifecycle Callback Events 
   onInitialize: function(){}, 
   onAutoCompleteSelected: function(item){},
   onSearchStart: function(){}, 
   onSearchCompleted: function(data){}, 
   onAddressFound: function(data){}, 

   //Error Callback
   onLookupError: function(){},

   //User Events Callback
   onChange: function(input){}, 
   onClear: function(){}, 
   onFocus: function(){}
})
</script> 

Search Lifecycle Callbacks in order

Option Description Type Default
onInitialize() Invoked once the Autoaddress plugin is completetly initialized. function() null
onAutoCompleteSelected(item) Invoked once an item has been selected from the autocomplete dropdown. function() null
onSearchStart() A request is about to be made to the FindAddress API. function() null
onSearchCompleted(data) Invoked when a response has been received from the FindAddress API search, the full response data is now available to you. Check the Find Address API page to examine the response format. This event is invoked after every search performed using the plugin. i.e. when the search button is hit or an item is selected from autocomplete. function() null
onAddressFound(data) Invoked when a response has been received from the FindAddress API search, the full response data is now available to you. Check the Find Address API page to examine the response format.

Similar to onSearchCompleted(data) but only fired when this is the final result for the search. This is the most important callback since this will only be called when the plugin has found a final result for the address or Eircode with no further options available.
function() null

Sample JSON(P) response for onSearchCompleted(data) & onAddressFound(data)

Once a search has been completed using the Find Address API i.e. via the user hitting the search button or selecting an item from autocomplete the onSearchCompleted(data) and onAddressFound(data) callbacks are called. The data parameter passed back to the callbacks contains the response from the API response. See below for an example of a JSON response.

{
  "result": {
    "code": 100,
    "text": "PostcodeAppended"
  },
  "postcode": "D08DW25",
  "addressId": 1700286134,
  "addressType": {
    "code": 2150,
    "text": "ResidentialAddressPoint"
  },
  "matchLevel": {
    "code": 2,
    "text": "AddressPoint"
  },
  "postalAddress": [
    "APARTMENT 49",
    "CAVALRY HOUSE",
    "CLANCY QUAY",
    "SOUTH CIRCULAR ROAD",
    "DUBLIN 8"
  ],
  "vanityAddress": null,
  "reformattedAddress": null,
  "totalOptions": 0,
  "options": [],
  "input": {
    "key": "YOUR_KEY",
    "txn": "fc1f98cd-605a-494e-b87c-06a8bfe2a629",
    "address": "APARTMENT 49, CAVALRY HOUSE, CLANCY QUAY, SOUTH CIRCULAR ROAD, DUBLIN 8",
    "addressId": 1700286134,
    "language": "en",
    "country": "ie",
    "smartGroupingIndex": null,
    "isVanityMode": false,
    "addressProfileName": null
  },
  "links": [
    {
      "rel": "self",
      "href": "http://api.autoaddress.ie/2.0/findaddress?key=YOUR_KEY&address=APARTMENT+49%2c+CAVALRY+HOUSE%2c+CLANCY+QUAY%2c+SOUTH+CIRCULAR+ROAD%2c+DUBLIN+8&addressId=1700286134&vanityMode=False"
    }
  ]
} 

Error Callbacks

Option Description Type Default
onLookupError(data) Invoked when an error has occured during a search. function() null

Sample JSON(P) response for onLookUpError(data)

When an error occurs within the Plugin, a message is returned detailing the source of the problem.

{
  "httpStatusCode": {
    "code": 401,
    "text": "Unauthorized"
  },
  "requestUrl": "https://api.autoaddress.ie/2.0/findaddress?key=YOUR_KEY&address=4%20INNS%20COURT%2C%20WINETAVERN%20STREET%2C%20DUBLIN%208&addressId=1004420615&limit=20&vanityMode=False&callback=foo",
  "errors": [
    {
      "type": {
        "code": 401005,
        "text": "AccessToRestrictedData"
      },
      "message": "Data unavailable.  Only sample addresses and dummy eircodes available.",
      "helpUrl": "http://www.autoaddress.ie"
    }
  ]
}

User Action Callbacks

Option Description Type Default
onChange(value) Invoked when the value of the input in the search field is changed. function() null
onClear() Invoked when the search field is cleared manually by the user. function() null
onFocus() Invoked when search fields gains Focus. function() null