Skip to content

Commit 00748ce

Browse files
authored
Add/Remove mark when region/zip is required (#2149)
1 parent 4a952b0 commit 00748ce

File tree

5 files changed

+72
-41
lines changed

5 files changed

+72
-41
lines changed

app/design/adminhtml/default/default/layout/sales.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,11 @@
485485
<block type="adminhtml/sales_transactions" name="sales_transactions.grid.container"></block>
486486
</reference>
487487
</adminhtml_sales_transactions_index>
488+
488489
<adminhtml_sales_transactions_grid>
489490
<block type="adminhtml/sales_transactions_grid" name="sales_transactions.grid" output="toHtml"></block>
490491
</adminhtml_sales_transactions_grid>
492+
491493
<adminhtml_sales_transactions_view>
492494
<reference name="content">
493495
<block type="adminhtml/sales_transactions_detail" name="sales_transactions.detail" template="sales/transactions/detail.phtml">
@@ -632,7 +634,6 @@
632634
</reference>
633635
</adminhtml_sales_order_create_load_block_header>
634636

635-
636637
<adminhtml_sales_order_create_load_block_sidebar>
637638
<reference name="content">
638639
<block type="adminhtml/sales_order_create_sidebar" template="sales/order/create/sidebar.phtml" name="sidebar">
@@ -1051,22 +1052,29 @@
10511052
<block type="adminhtml/sales_order_status" name="sales_order_status.grid.container"></block>
10521053
</reference>
10531054
</adminhtml_sales_order_status_index>
1055+
10541056
<adminhtml_sales_order_status_new>
10551057
<reference name="content">
10561058
<block type="adminhtml/sales_order_status_new" name="sales_order_status.new.container"></block>
10571059
</reference>
10581060
</adminhtml_sales_order_status_new>
1061+
10591062
<adminhtml_sales_order_status_edit>
10601063
<reference name="content">
10611064
<block type="adminhtml/sales_order_status_edit" name="sales_order_status.edit.container"></block>
10621065
</reference>
10631066
</adminhtml_sales_order_status_edit>
1067+
10641068
<adminhtml_sales_order_status_assign>
10651069
<reference name="content">
10661070
<block type="adminhtml/sales_order_status_assign" name="sales_order_status.assign.container"></block>
10671071
</reference>
10681072
</adminhtml_sales_order_status_assign>
1073+
10691074
<adminhtml_sales_order_address>
1075+
<reference name="head">
1076+
<block type="adminhtml/template" name="optional_zip_countries" as="optional_zip_countries" template="directory/js/optional_zip_countries.phtml" />
1077+
</reference>
10701078
<reference name="content">
10711079
<block type="adminhtml/sales_order_address" name="sales_order_address.form.container"></block>
10721080
</reference>

app/design/adminhtml/default/default/template/customer/tab/addresses.phtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ addressesModel.prototype = {
586586
label = $$('label[for="' + currentElement.id + '"]')[0];
587587
if (label) {
588588
wildCard = label.down('em') || label.down('span.required');
589+
if (!wildCard) {
590+
label.insert(' <span class="required">*</span>');
591+
wildCard = label.down('span.required');
592+
}
589593
if (!that.showAllRegions) {
590594
if (regionRequired) {
591595
label.up('tr').show();

app/design/adminhtml/default/default/template/directory/js/optional_zip_countries.phtml

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,5 @@
2929
<script type="text/javascript">
3030
//<![CDATA[
3131
optionalZipCountries = <?php echo $this->helper('directory')->getCountriesWithOptionalZip(true) ?>;
32-
33-
function onAddressCountryChanged (countryElement) {
34-
var zipElementId = countryElement.id.replace(/country_id/, 'postcode');
35-
36-
// Ajax-request and normal content load compatibility
37-
if ($(zipElementId) != undefined) {
38-
setPostcodeOptional($(zipElementId), countryElement.value);
39-
} else {
40-
Event.observe(window, "load", function () {
41-
setPostcodeOptional($(zipElementId), countryElement.value);
42-
});
43-
}
44-
}
45-
46-
function setPostcodeOptional(zipElement, country) {
47-
if (optionalZipCountries.indexOf(country) != -1) {
48-
while (zipElement.hasClassName('required-entry')) {
49-
zipElement.removeClassName('required-entry');
50-
}
51-
zipElement.up(1).down('label > span.required').hide();
52-
} else {
53-
zipElement.addClassName('required-entry');
54-
zipElement.up(1).down('label > span.required').show();
55-
}
56-
}
57-
58-
varienGlobalEvents.attachEventHandler("address_country_changed", onAddressCountryChanged);
5932
//]]>
6033
</script>

js/mage/adminhtml/form.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ RegionUpdater.prototype = {
222222
label = $$('label[for="' + currentElement.id + '"]')[0];
223223
if (label) {
224224
wildCard = label.down('em') || label.down('span.required');
225+
if (!wildCard) {
226+
label.insert(' <span class="required">*</span>');
227+
wildCard = label.down('span.required');
228+
}
225229
var topElement = label.up('tr') || label.up('li');
226230
if (!that.config.show_all_regions && topElement) {
227231
if (regionRequired) {
@@ -576,3 +580,35 @@ FormElementDependenceController.prototype = {
576580
}
577581
}
578582
};
583+
584+
// optional_zip_countries.phtml
585+
function onAddressCountryChanged(countryElement) {
586+
var zipElementId = countryElement.id.replace(/country_id/, 'postcode');
587+
// Ajax-request and normal content load compatibility
588+
if ($(zipElementId) != undefined) {
589+
setPostcodeOptional($(zipElementId), countryElement.value);
590+
} else {
591+
Event.observe(window, "load", function () {
592+
setPostcodeOptional($(zipElementId), countryElement.value);
593+
});
594+
}
595+
}
596+
597+
function setPostcodeOptional(zipElement, country) {
598+
var spanElement = zipElement.up(1).down('label > span.required');
599+
if (!spanElement || (typeof optionalZipCountries == 'undefined')) {
600+
return; // nothing to do (for example in system config)
601+
}
602+
if (optionalZipCountries.indexOf(country) != -1) {
603+
Validation.reset(zipElement);
604+
while (zipElement.hasClassName('required-entry')) {
605+
zipElement.removeClassName('required-entry');
606+
}
607+
spanElement.hide();
608+
} else {
609+
zipElement.addClassName('required-entry');
610+
spanElement.show();
611+
}
612+
}
613+
614+
varienGlobalEvents.attachEventHandler("address_country_changed", onAddressCountryChanged);

js/varien/form.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
1717
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
1818
*/
19+
1920
VarienForm = Class.create();
2021
VarienForm.prototype = {
2122
initialize: function(formId, firstFieldFocus){
@@ -156,8 +157,7 @@ VarienForm.prototype = {
156157

157158
RegionUpdater = Class.create();
158159
RegionUpdater.prototype = {
159-
initialize: function (countryEl, regionTextEl, regionSelectEl, regions, disableAction, zipEl)
160-
{
160+
initialize: function (countryEl, regionTextEl, regionSelectEl, regions, disableAction, zipEl){
161161
this.countryEl = $(countryEl);
162162
this.regionTextEl = $(regionTextEl);
163163
this.regionSelectEl = $(regionSelectEl);
@@ -176,8 +176,7 @@ RegionUpdater.prototype = {
176176
Event.observe(this.countryEl, 'change', this.update.bind(this));
177177
},
178178

179-
_checkRegionRequired: function()
180-
{
179+
_checkRegionRequired: function(){
181180
var label, wildCard;
182181
var elements = [this.regionTextEl, this.regionSelectEl];
183182
var that = this;
@@ -191,6 +190,10 @@ RegionUpdater.prototype = {
191190
label = $$('label[for="' + currentElement.id + '"]')[0];
192191
if (label) {
193192
wildCard = label.down('em') || label.down('span.required');
193+
if (!wildCard) {
194+
label.insert(' <span class="required">*</span>');
195+
wildCard = label.down('span.required');
196+
}
194197
if (!that.config.show_all_regions) {
195198
if (regionRequired) {
196199
label.up().show();
@@ -234,8 +237,7 @@ RegionUpdater.prototype = {
234237
});
235238
},
236239

237-
update: function()
238-
{
240+
update: function(){
239241
if (this.regions[this.countryEl.value]) {
240242
var i, option, region, def;
241243

@@ -332,7 +334,8 @@ RegionUpdater.prototype = {
332334
}
333335
}
334336
},
335-
sortSelect : function () {
337+
338+
sortSelect: function () {
336339
var elem = this.regionSelectEl;
337340
var tmpArray = new Array();
338341
var currentVal = $(elem).value;
@@ -356,14 +359,12 @@ RegionUpdater.prototype = {
356359

357360
ZipUpdater = Class.create();
358361
ZipUpdater.prototype = {
359-
initialize: function(country, zipElement)
360-
{
362+
initialize: function(country, zipElement){
361363
this.country = country;
362364
this.zipElement = $(zipElement);
363365
},
364366

365-
update: function()
366-
{
367+
update: function(){
367368
// Country ISO 2-letter codes must be pre-defined
368369
if (typeof optionalZipCountries == 'undefined') {
369370
return false;
@@ -378,8 +379,7 @@ ZipUpdater.prototype = {
378379
}
379380
},
380381

381-
_setPostcodeOptional: function()
382-
{
382+
_setPostcodeOptional: function(){
383383
this.zipElement = $(this.zipElement);
384384
if (this.zipElement == undefined) {
385385
return false;
@@ -389,17 +389,27 @@ ZipUpdater.prototype = {
389389
var label = $$('label[for="' + this.zipElement.id + '"]')[0];
390390
if (label != undefined) {
391391
var wildCard = label.down('em') || label.down('span.required');
392+
if (!wildCard) {
393+
label.insert(' <span class="required">*</span>');
394+
wildCard = label.down('span.required');
395+
}
392396
}
393397

394398
// Make Zip and its label required/optional
395399
if (optionalZipCountries.indexOf(this.country) != -1) {
400+
if (label.hasClassName('required')) {
401+
label.removeClassName('required');
402+
}
396403
while (this.zipElement.hasClassName('required-entry')) {
397404
this.zipElement.removeClassName('required-entry');
398405
}
399406
if (wildCard != undefined) {
400407
wildCard.hide();
401408
}
402409
} else {
410+
if (!label.hasClassName('required')) {
411+
label.addClassName('required');
412+
}
403413
this.zipElement.addClassName('required-entry');
404414
if (wildCard != undefined) {
405415
wildCard.show();

0 commit comments

Comments
 (0)