Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Magento postal code javascript error: error: error in [unknown object].fireEvent(): event name: address_country_changed error message: zipElement.up(1).down("label > span.required") is undefined Fix! ___ Update file: app\design\adminhtml\default\default\template\directory\js\optional_zip_countries.phtml
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category design
* @package default_default
* @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/
?>
<?php
/**
* JS block for including Countries with Optional Zip
*
* @see Mage_Adminhtml_Block_Template
*/
?>
<script type="text/javascript">
//<![CDATA[
optionalZipCountries = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;
function onAddressCountryChanged (countryElement) {
var zipElementId = countryElement.id.replace(/country_id/, 'postcode');
// Ajax-request and normal content load compatibility
if ($(zipElementId) != undefined) {
setPostcodeOptional($(zipElementId), countryElement.value);
} else {
Event.observe(window, "load", function () {
setPostcodeOptional($(zipElementId), countryElement.value);
});
}
}
function setPostcodeOptional(zipElement, country) {
if (optionalZipCountries.indexOf(country) != -1) {
while (zipElement.hasClassName('required-entry')) {
zipElement.removeClassName('required-entry');
}
// zipElement.up(1).down('label > span.required').hide();
var zipElementLabel = zipElement.up(1).down('label > span.required');
if (zipElementLabel) zipElementLabel.hide();
} else {
zipElement.addClassName('required-entry');
// zipElement.up(1).down('label > span.required').show();
var zipElementLabel = zipElement.up(1).down('label > span.required');
if (zipElementLabel) zipElementLabel.show();
}
}
varienGlobalEvents.attachEventHandler("address_country_changed", onAddressCountryChanged);
//]]>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.