Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/Remove mark when region/zip is required #2149

Merged
merged 2 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion app/design/adminhtml/default/default/layout/sales.xml
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,11 @@
<block type="adminhtml/sales_transactions" name="sales_transactions.grid.container"></block>
</reference>
</adminhtml_sales_transactions_index>

<adminhtml_sales_transactions_grid>
<block type="adminhtml/sales_transactions_grid" name="sales_transactions.grid" output="toHtml"></block>
</adminhtml_sales_transactions_grid>

<adminhtml_sales_transactions_view>
<reference name="content">
<block type="adminhtml/sales_transactions_detail" name="sales_transactions.detail" template="sales/transactions/detail.phtml">
Expand Down Expand Up @@ -638,7 +640,6 @@
</reference>
</adminhtml_sales_order_create_load_block_header>


<adminhtml_sales_order_create_load_block_sidebar>
<reference name="content">
<block type="adminhtml/sales_order_create_sidebar" template="sales/order/create/sidebar.phtml" name="sidebar">
Expand Down Expand Up @@ -1057,22 +1058,29 @@
<block type="adminhtml/sales_order_status" name="sales_order_status.grid.container"></block>
</reference>
</adminhtml_sales_order_status_index>

<adminhtml_sales_order_status_new>
<reference name="content">
<block type="adminhtml/sales_order_status_new" name="sales_order_status.new.container"></block>
</reference>
</adminhtml_sales_order_status_new>

<adminhtml_sales_order_status_edit>
<reference name="content">
<block type="adminhtml/sales_order_status_edit" name="sales_order_status.edit.container"></block>
</reference>
</adminhtml_sales_order_status_edit>

<adminhtml_sales_order_status_assign>
<reference name="content">
<block type="adminhtml/sales_order_status_assign" name="sales_order_status.assign.container"></block>
</reference>
</adminhtml_sales_order_status_assign>

<adminhtml_sales_order_address>
<reference name="head">
<block type="adminhtml/template" name="optional_zip_countries" as="optional_zip_countries" template="directory/js/optional_zip_countries.phtml" />
</reference>
<reference name="content">
<block type="adminhtml/sales_order_address" name="sales_order_address.form.container"></block>
</reference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ addressesModel.prototype = {
label = $$('label[for="' + currentElement.id + '"]')[0];
if (label) {
wildCard = label.down('em') || label.down('span.required');
if (!wildCard) {
label.insert(' <span class="required">*</span>');
wildCard = label.down('span.required');
}
if (!that.showAllRegions) {
if (regionRequired) {
label.up('tr').show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,5 @@
<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();
} else {
zipElement.addClassName('required-entry');
zipElement.up(1).down('label > span.required').show();
}
}

varienGlobalEvents.attachEventHandler("address_country_changed", onAddressCountryChanged);
//]]>
</script>
36 changes: 36 additions & 0 deletions js/mage/adminhtml/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ RegionUpdater.prototype = {
label = $$('label[for="' + currentElement.id + '"]')[0];
if (label) {
wildCard = label.down('em') || label.down('span.required');
if (!wildCard) {
label.insert(' <span class="required">*</span>');
wildCard = label.down('span.required');
}
var topElement = label.up('tr') || label.up('li');
if (!that.config.show_all_regions && topElement) {
if (regionRequired) {
Expand Down Expand Up @@ -582,3 +586,35 @@ FormElementDependenceController.prototype = {
}
}
};

// optional_zip_countries.phtml
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) {
var spanElement = zipElement.up(1).down('label > span.required');
if (!spanElement || (typeof optionalZipCountries == 'undefined')) {
return; // nothing to do (for example in system config)
}
if (optionalZipCountries.indexOf(country) != -1) {
Validation.reset(zipElement);
while (zipElement.hasClassName('required-entry')) {
zipElement.removeClassName('required-entry');
}
spanElement.hide();
} else {
zipElement.addClassName('required-entry');
spanElement.show();
}
}

varienGlobalEvents.attachEventHandler("address_country_changed", onAddressCountryChanged);
36 changes: 23 additions & 13 deletions js/varien/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
*/

VarienForm = Class.create();
VarienForm.prototype = {
initialize: function(formId, firstFieldFocus){
Expand Down Expand Up @@ -162,8 +163,7 @@ VarienForm.prototype = {

RegionUpdater = Class.create();
RegionUpdater.prototype = {
initialize: function (countryEl, regionTextEl, regionSelectEl, regions, disableAction, zipEl)
{
initialize: function (countryEl, regionTextEl, regionSelectEl, regions, disableAction, zipEl){
this.countryEl = $(countryEl);
this.regionTextEl = $(regionTextEl);
this.regionSelectEl = $(regionSelectEl);
Expand All @@ -182,8 +182,7 @@ RegionUpdater.prototype = {
Event.observe(this.countryEl, 'change', this.update.bind(this));
},

_checkRegionRequired: function()
{
_checkRegionRequired: function(){
var label, wildCard;
var elements = [this.regionTextEl, this.regionSelectEl];
var that = this;
Expand All @@ -197,6 +196,10 @@ RegionUpdater.prototype = {
label = $$('label[for="' + currentElement.id + '"]')[0];
if (label) {
wildCard = label.down('em') || label.down('span.required');
if (!wildCard) {
label.insert(' <span class="required">*</span>');
wildCard = label.down('span.required');
}
if (!that.config.show_all_regions) {
if (regionRequired) {
label.up().show();
Expand Down Expand Up @@ -240,8 +243,7 @@ RegionUpdater.prototype = {
});
},

update: function()
{
update: function(){
if (this.regions[this.countryEl.value]) {
var i, option, region, def;

Expand Down Expand Up @@ -338,7 +340,8 @@ RegionUpdater.prototype = {
}
}
},
sortSelect : function () {

sortSelect: function () {
var elem = this.regionSelectEl;
var tmpArray = new Array();
var currentVal = $(elem).value;
Expand All @@ -362,14 +365,12 @@ RegionUpdater.prototype = {

ZipUpdater = Class.create();
ZipUpdater.prototype = {
initialize: function(country, zipElement)
{
initialize: function(country, zipElement){
this.country = country;
this.zipElement = $(zipElement);
},

update: function()
{
update: function(){
// Country ISO 2-letter codes must be pre-defined
if (typeof optionalZipCountries == 'undefined') {
return false;
Expand All @@ -384,8 +385,7 @@ ZipUpdater.prototype = {
}
},

_setPostcodeOptional: function()
{
_setPostcodeOptional: function(){
this.zipElement = $(this.zipElement);
if (this.zipElement == undefined) {
return false;
Expand All @@ -395,17 +395,27 @@ ZipUpdater.prototype = {
var label = $$('label[for="' + this.zipElement.id + '"]')[0];
if (label != undefined) {
var wildCard = label.down('em') || label.down('span.required');
if (!wildCard) {
label.insert(' <span class="required">*</span>');
wildCard = label.down('span.required');
}
}

// Make Zip and its label required/optional
if (optionalZipCountries.indexOf(this.country) != -1) {
if (label.hasClassName('required')) {
label.removeClassName('required');
}
while (this.zipElement.hasClassName('required-entry')) {
this.zipElement.removeClassName('required-entry');
}
if (wildCard != undefined) {
wildCard.hide();
}
} else {
if (!label.hasClassName('required')) {
label.addClassName('required');
}
this.zipElement.addClassName('required-entry');
if (wildCard != undefined) {
wildCard.show();
Expand Down