Skip to main content

jQuery Plugin Migration

This guide helps you migrate from GetAddress's jQuery Find plugin to Ideal Postcodes' jquery.postcodes plugin.

Both plugins provide postcode lookup functionality for jQuery-based forms, allowing users to enter a postcode and select their address from a dropdown list.

Key Similarities & Differences

FeatureGetAddress jQueryIdeal Postcodes jQuery
jQuery VersionjQuery 2+jQuery 1.9+
Initialization$().getAddress()$().setupPostcodeLookup()
Field BindingCSS selectors via output_fieldsCSS selectors via output_fields

Complete Example: Before & After

GetAddress jQuery

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.getaddress.io/scripts/jquery.getAddress-4.0.0.js"></script>
<form>
<div id="postcode_lookup"></div>

<label>Address Line 1</label>
<input id="line1" type="text" />

<label>Address Line 2</label>
<input id="line2" type="text" />

<label>Address Line 3</label>
<input id="line3" type="text" />

<label>Town</label>
<input id="town" type="text" />

<label>County</label>
<input id="county" type="text" />

<label>Postcode</label>
<input id="postcode" type="text" />
</form>

<script>
$("#postcode_lookup").getAddress({
api_key: "YOUR_GETADDRESS_API_KEY",
output_fields: {
line_1: "#line1",
line_2: "#line2",
line_3: "#line3",
post_town: "#town",
county: "#county",
postcode: "#postcode",
},
});
</script>

Ideal Postcodes jQuery

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery-postcodes@3/dist/postcodes.min.js"></script>
<form>
<div id="postcode_lookup"></div>

<label>Address Line 1</label>
<input id="line1" type="text" />

<label>Address Line 2</label>
<input id="line2" type="text" />

<label>Address Line 3</label>
<input id="line3" type="text" />

<label>Town</label>
<input id="town" type="text" />

<label>County</label>
<input id="county" type="text" />

<label>Postcode</label>
<input id="postcode" type="text" />
</form>

<script>
$("#postcode_lookup").setupPostcodeLookup({
api_key: "YOUR_IDEAL_POSTCODES_API_KEY",
output_fields: {
line_1: "#line1",
line_2: "#line2",
line_3: "#line3",
post_town: "#town",
county: "#county",
postcode: "#postcode",
},
});
</script>

Step-by-Step Migration

Step 1: Replace Script

GetAddress jQuery

<script src="https://cdn.getaddress.io/scripts/jquery.getAddress-4.0.0.js"></script>

Ideal Postcodes jQuery

<script src="https://cdn.jsdelivr.net/npm/jquery-postcodes@3/dist/postcodes.min.js"></script>

Step 2: Update Initialization

GetAddress jQuery

$("#postcode_lookup").getAddress({
api_key: "YOUR_GETADDRESS_API_KEY",
output_fields: {
line_1: "#line1",
line_2: "#line2",
line_3: "#line3",
post_town: "#town",
county: "#county",
postcode: "#postcode",
},
});

Ideal Postcodes jQuery

$("#postcode_lookup").setupPostcodeLookup({
api_key: "YOUR_IDEAL_POSTCODES_API_KEY",
output_fields: {
line_1: "#line1",
line_2: "#line2",
line_3: "#line3",
post_town: "#town",
county: "#county",
postcode: "#postcode",
},
});

Key Changes:

  • Method name: .getAddress().setupPostcodeLookup()
  • API key: Replace with your Ideal Postcodes API key
  • Field mapping: Uses same output_fields structure with CSS selectors

Step 3: Update Field Names

The field names are largely compatible. The main difference is town_or_city in GetAddress maps to post_town in Ideal Postcodes:

GetAddress FieldIdeal Postcodes FieldDescription
line_1line_1First address line
line_2line_2Second address line
line_3line_3Third address line
post_townpost_townTown/City
countycountyCounty
postcodepostcodePostcode

For additional field mappings, see the Address Field Mapping Reference.

Migrating Callbacks

Both plugins support callbacks, but with different names and signatures:

GetAddress CallbackIdeal Postcodes CallbackDescription
onLookupSuccessonAddressesRetrievedAddresses returned from API
onLookupErroronSearchErrorAPI returned an error
onAddressSelectedonAddressSelectedUser selected an address
N/AonSearchCompletedSearch completed (success/fail)
N/AonLoadedPlugin initialized
N/AonFailedCheckAPI key validation failed
N/AonDropdownCreatedDropdown added to DOM
N/AonDropdownDestroyedDropdown removed from DOM
N/AonLookupTriggeredUser clicked search button
N/AshouldLookupTriggerControl whether lookup proceeds

Callback Migration Example

GetAddress jQuery

$("#postcode_lookup").getAddress({
api_key: "YOUR_API_KEY",
output_fields: {
line_1: "#line1",
post_town: "#town",
postcode: "#postcode",
},
onLookupSuccess: function (data) {
console.log("Found addresses:", data);
},
onLookupError: function () {
console.log("Lookup failed");
},
// Receives { id, text } object
onAddressSelected: function (selected) {
console.log("Selected:", selected.text);
},
});

Ideal Postcodes jQuery

$("#postcode_lookup").setupPostcodeLookup({
api_key: "YOUR_API_KEY",
output_fields: {
line_1: "#line1",
post_town: "#town",
postcode: "#postcode",
},
onAddressesRetrieved: function (addresses) {
console.log("Found addresses:", addresses);
},
onSearchError: function (error) {
console.log("Lookup failed:", error);
},
// Receives full address object
onAddressSelected: function (address) {
console.log("Selected:", address.line_1);
},
});

Key Differences:

  • onLookupSuccessonAddressesRetrieved: Both receive array of addresses
  • onLookupErroronSearchError: Ideal Postcodes passes error object with details
  • onAddressSelected: GetAddress passes { id, text } object, Ideal Postcodes passes the full address object with all fields

Configuration Options Mapping

Most configuration options have direct equivalents:

GetAddress OptionIdeal Postcodes OptionNotes
api_keyapi_keyDirect match
inputinputDirect match
input_labelinput_labelDirect match
input_classinput_classDirect match
input_idinput_idDirect match
input_muted_styleinput_muted_styleDirect match
buttonbuttonDirect match
button_labelbutton_labelDirect match
button_classbutton_classDirect match
button_idbutton_idDirect match
button_disabled_messagebutton_disabled_messageDirect match
dropdown_iddropdown_idDirect match
dropdown_classdropdown_classDirect match
dropdown_select_messagedropdown_select_messageDirect match
error_message_postcode_invaliderror_message_invalid_postcodeRenamed
error_message_postcode_not_founderror_message_not_foundRenamed
error_message_defaulterror_message_defaultDirect match
error_message_classerror_message_classDirect match
lookup_intervaldisable_intervalRenamed (same functionality)
timeoutN/AFixed at 10000ms
input_nameN/ANot supported

Additional Configuration Options

Ideal Postcodes jquery.postcodes supports additional configuration not available in GetAddress:

$("#postcode_lookup").setupPostcodeLookup({
api_key: "YOUR_API_KEY",
output_fields: {
line_1: "#line1",
line_2: "#line2",
line_3: "#line3",
post_town: "#town",
postcode: "#postcode",
},

// API Configuration
endpoint: "https://api.ideal-postcodes.co.uk/v1", // Custom API endpoint
licensee: "your_licensee_key", // Optional licensee key
tags: ["source:website"], // Request tagging for analytics

// Behaviour
check_key: true, // Validate API key on init
remove_organisation: true, // Remove org names from address lines
address_search: false, // Enable fallback to address search
debug_mode: false, // Show API errors to user

// Custom Containers
dropdown_container: "#custom_dropdown_area",
error_message_container: "#custom_error_area",
});

Using Custom Input and Button

Both plugins support using existing form elements:

GetAddress jQuery

$("#postcode_lookup").getAddress({
api_key: "YOUR_API_KEY",
input: "#my_postcode_input",
button: "#my_search_button",
output_fields: {
line_1: "#line1",
post_town: "#town",
postcode: "#postcode",
},
});

Ideal Postcodes jQuery

$("#postcode_lookup").setupPostcodeLookup({
api_key: "YOUR_API_KEY",
input: "#my_postcode_input",
button: "#my_search_button",
output_fields: {
line_1: "#line1",
post_town: "#town",
postcode: "#postcode",
},
});

Both plugins use the same input and button options to reference existing elements.

Need Help?

We are available 9am to 5pm UK time on chat or email support@ideal-postcodes.co.uk for migration assistance.