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