Skip to content

Commit edc9614

Browse files
ENGCOM-5468: Resolve Rule coupon code generate form validation issue23778 #23781
2 parents 5536404 + f0d6476 commit edc9614

File tree

2 files changed

+27
-5
lines changed
  • app/code/Magento/SalesRule

2 files changed

+27
-5
lines changed

app/code/Magento/SalesRule/Block/Adminhtml/Promo/Quote/Edit/Tab/Coupons/Form.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab\Coupons;
79

810
/**
911
* Coupons generation parameters form
1012
*
1113
* @author Magento Core Team <core@magentocommerce.com>
14+
*
15+
* Class \Magento\SalesRule\Block\Adminhtml\Promo\Quote\Edit\Tab\Coupons\Form
1216
*/
1317
class Form extends \Magento\Backend\Block\Widget\Form\Generic
1418
{
@@ -77,7 +81,8 @@ protected function _prepareForm()
7781
'label' => __('Coupon Qty'),
7882
'title' => __('Coupon Qty'),
7983
'required' => true,
80-
'class' => 'validate-digits validate-greater-than-zero'
84+
'class' => 'validate-digits validate-greater-than-zero',
85+
'onchange' => 'window.validateCouponGenerate(this)'
8186
]
8287
);
8388

@@ -91,7 +96,8 @@ protected function _prepareForm()
9196
'required' => true,
9297
'note' => __('Excluding prefix, suffix and separators.'),
9398
'value' => $couponHelper->getDefaultLength(),
94-
'class' => 'validate-digits validate-greater-than-zero'
99+
'class' => 'validate-digits validate-greater-than-zero',
100+
'onchange' => 'window.validateCouponGenerate(this)'
95101
]
96102
);
97103

@@ -103,7 +109,8 @@ protected function _prepareForm()
103109
'name' => 'format',
104110
'options' => $couponHelper->getFormatsList(),
105111
'required' => true,
106-
'value' => $couponHelper->getDefaultFormat()
112+
'value' => $couponHelper->getDefaultFormat(),
113+
'onchange' => 'window.validateCouponGenerate(this)'
107114
]
108115
);
109116

@@ -138,7 +145,8 @@ protected function _prepareForm()
138145
'title' => __('Dash Every X Characters'),
139146
'note' => __('If empty no separation.'),
140147
'value' => $couponHelper->getDefaultDashInterval(),
141-
'class' => 'validate-digits'
148+
'class' => 'validate-digits',
149+
'onchange' => 'window.validateCouponGenerate(this)'
142150
]
143151
);
144152

app/code/Magento/SalesRule/view/adminhtml/templates/promo/salesrulejs.phtml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ function refreshCouponCodesGrid(grid, gridMassAction, transport) {
2020

2121
function generateCouponCodes(idPrefix, generateUrl, grid) {
2222
$(idPrefix + 'information_fieldset').removeClassName('ignore-validate');
23+
var listInvalidElement = [];
2324
var validationResult = $(idPrefix + 'information_fieldset').select('input',
2425
'select', 'textarea').collect( function(elm) {
25-
return jQuery.validator.validateElement(elm);
26+
var validateOneElementResult = jQuery.validator.validateSingleElement(elm);
27+
if (!validateOneElementResult) {
28+
listInvalidElement.push(elm);
29+
}
30+
return validateOneElementResult;
2631
}).all();
32+
if (listInvalidElement.length) {
33+
listInvalidElement[0].focus();
34+
}
35+
2736
$(idPrefix + 'information_fieldset').addClassName('ignore-validate');
2837

2938
if (!validationResult) {
@@ -77,6 +86,11 @@ function generateCouponCodes(idPrefix, generateUrl, grid) {
7786
});
7887
}
7988

89+
function validateCouponGenerate(elm) {
90+
jQuery.validator.validateSingleElement(elm);
91+
}
92+
93+
window.validateCouponGenerate = validateCouponGenerate;
8094
window.generateCouponCodes = generateCouponCodes;
8195
window.refreshCouponCodesGrid = refreshCouponCodesGrid;
8296
});

0 commit comments

Comments
 (0)