Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Autocomplete Country ajax request parameter should update when country select has changed #48

Open
jonathanpbailey2 opened this issue Feb 11, 2015 · 0 comments

Comments

@jonathanpbailey2
Copy link

The code currently only set the parameter to the initial value of the Shipping/Billing country. It should update each time the country is changed. I took the liberty of fixing. Here is the updated postcode-checkout.phtml

isPostcodeAutocompleteEnabled()): ?> <script type="text/javascript"> var citySuggestUrl = 'helper('australia')->getCitySuggestUrl(); ?>'; //============ Billing ============// var autocomplete_city_billing = new Element('div', { id: 'autocomplete_city_billing', 'class': 'fontis-postcode-autocomplete' }); var billing_completer; var shipping_completer; if ($('billing:city')) { $('billing:city').parentNode.appendChild(autocomplete_city_billing); function updateAddressBilling(text, item) { // Update state and postcode fields var id = item.id; var tokens = id.split('-'); // Assume item at index 1 is region_id, item at index 3 is postcode $('billing:region_id').value = tokens[1]; $('billing:postcode').value = tokens[3]; } // Create the autocompleter and assign it to a variable for future use. billing_completer = new Ajax.Autocompleter("billing:city", "autocomplete_city_billing", citySuggestUrl, { afterUpdateElement: updateAddressBilling, minChars: 2, parameters: 'country=' + $F('billing:country_id') }); } $('billing:country_id').observe('change', function(event) { billing_completer.options.defaultParams = 'country=' + $F('billing:country_id'); }); //============ Shipping ============// var autocomplete_city_shipping = new Element('div', { id: 'autocomplete_city_shipping', 'class': 'fontis-postcode-autocomplete' }); if ($('shipping:city')) { $('shipping:city').parentNode.appendChild(autocomplete_city_shipping); function updateAddressShipping(text, item) { // Update state and postcode fields var id = item.id; var tokens = id.split('-'); // Assume item at index 1 is region_id, item at index 3 is postcode $('shipping:region_id').value = tokens[1]; $('shipping:postcode').value = tokens[3]; } // Create the autocompleter and assign it to a variable for future use. shipping_completer = new Ajax.Autocompleter("shipping:city", "autocomplete_city_shipping", citySuggestUrl, { afterUpdateElement: updateAddressShipping, minChars: 2, parameters: 'country=' + $F('shipping:country_id') }); } $('shipping:country_id').observe('change', function(event) { shipping_completer.options.defaultParams = 'country=' + $F('shipping:country_id'); }); </script>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant