| 1 |
/**
|
| 2 |
* $Id: addresses.js,v 1.1 2008/01/30 08:59:10 brmassa Exp $
|
| 3 |
* @author Bruno Massa
|
| 4 |
* @file addresses.js
|
| 5 |
* Autocompletion for Province field.
|
| 6 |
* This jQuery function will force the Province field
|
| 7 |
* to autcomplete the pronvice for a given country.
|
| 8 |
*/
|
| 9 |
/*global Drupal, $ */
|
| 10 |
|
| 11 |
Drupal.behaviors.addresses = function(context) {
|
| 12 |
// Use this ID to 'simplify' the callings
|
| 13 |
var id = '#edit-addresses-';
|
| 14 |
|
| 15 |
// Record the original URL
|
| 16 |
var url = Drupal.settings.absPath + '/admin/settings/addresses/autocomplete/';
|
| 17 |
|
| 18 |
// Get all address
|
| 19 |
for (var n = 0; true; n++) {
|
| 20 |
// Check if this Field exists.
|
| 21 |
// If not, stop the script
|
| 22 |
if (!$(id + n +'-country').length) {
|
| 23 |
break;
|
| 24 |
}
|
| 25 |
|
| 26 |
// Set the country code at the beginning
|
| 27 |
if ($(id + n +'-country').val()) {
|
| 28 |
$(id + n +'-province-autocomplete').val(url + $(id + n +'-country').val());
|
| 29 |
}
|
| 30 |
|
| 31 |
// Change the country code everytime the country field changes
|
| 32 |
$(id + n +'-country').change(function() {
|
| 33 |
$(id + n +'-province-autocomplete').val(url + $(this).val());
|
| 34 |
// Drupal.behaviors.autocomplete();
|
| 35 |
});
|
| 36 |
}
|
| 37 |
};
|