Skip to content

Instantly share code, notes, and snippets.

@dzungtran
Created May 8, 2014 03:43
Show Gist options
  • Save dzungtran/a246ef01619df077562f to your computer and use it in GitHub Desktop.
Save dzungtran/a246ef01619df077562f to your computer and use it in GitHub Desktop.
Magento form : Fix region update select box for uniform
/**
* Fix for uniform.js
* Override RegionUpdater class
*/
if (typeof RegionUpdater !== 'undefined') {
RegionUpdater.prototype.update = RegionUpdater.prototype.update.wrap(function(callOriginal) {
/* Check uniform */
if (typeof jQuery !== 'undefined' && typeof jQuery.uniform !== 'undefined') {
if (this.regions[this.countryEl.value]) {
var i, option, region, def;
def = this.regionSelectEl.getAttribute('defaultValue');
if (this.regionTextEl) {
if (!def) {
def = this.regionTextEl.value.toLowerCase();
}
this.regionTextEl.value = '';
}
this.regionSelectEl.options.length = 1;
for (regionId in this.regions[this.countryEl.value]) {
region = this.regions[this.countryEl.value][regionId];
option = document.createElement('OPTION');
option.value = regionId;
option.text = region.name.stripTags();
option.title = region.name;
if (this.regionSelectEl.options.add) {
this.regionSelectEl.options.add(option);
} else {
this.regionSelectEl.appendChild(option);
}
if (regionId == def || (region.name && region.name.toLowerCase() == def) ||
(region.name && region.code.toLowerCase() == def)
) {
this.regionSelectEl.value = regionId;
}
}
if (this.disableAction == 'hide') {
if (this.regionTextEl) {
this.regionTextEl.style.display = 'none';
// fix uniform
//$(this.regionTextEl.id).hide();
}
this.regionSelectEl.style.display = '';
// fix uniform
if($('uniform-' + this.regionSelectEl.id)){
$('uniform-' + this.regionSelectEl.id).show();
}
} else if (this.disableAction == 'disable') {
if (this.regionTextEl) {
this.regionTextEl.disabled = true;
}
this.regionSelectEl.disabled = false;
}
this.setMarkDisplay(this.regionSelectEl, true);
} else {
this.regionSelectEl.options.length = 1;
if (this.disableAction == 'hide') {
if (this.regionTextEl) {
this.regionTextEl.style.display = '';
// fix uniform
//$(this.regionTextEl.id).show();
}
this.regionSelectEl.style.display = 'none';
// fix uniform
if($('uniform-' + this.regionSelectEl.id)){
$('uniform-' + this.regionSelectEl.id).hide();
}
Validation.reset(this.regionSelectEl);
} else if (this.disableAction == 'disable') {
if (this.regionTextEl) {
this.regionTextEl.disabled = false;
}
this.regionSelectEl.disabled = true;
} else if (this.disableAction == 'nullify') {
this.regionSelectEl.options.length = 1;
this.regionSelectEl.value = '';
this.regionSelectEl.selectedIndex = 0;
this.lastCountryId = '';
}
this.setMarkDisplay(this.regionSelectEl, false);
}
this._checkRegionRequired();
// Make Zip and its label required/optional
var zipUpdater = new ZipUpdater(this.countryEl.value, this.zipEl);
zipUpdater.update();
} else {
callOriginal();
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment