Skip to content

Commit 65a2c17

Browse files
committed
add orig-name to elements when _prepareArrayInputs and use it for name validation if it exists
1 parent 156ac16 commit 65a2c17

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

lib/web/mage/validation.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,7 +1885,8 @@
18851885
*/
18861886
_prepareArrayInputs: function () {
18871887
/* Store original names for array inputs */
1888-
var originalElements = [];
1888+
var originalElements = [],
1889+
originalSubmitHandler = this.options.submitHandler;
18891890

18901891
/* For all array inputs, assign index so that validation is proper */
18911892
this.element.find('[name$="[]"]').each(function (key, input) {
@@ -1895,6 +1896,7 @@
18951896
originalName = input.attr('name');
18961897
name = originalName.replace('[]', '[' + key + ']');
18971898
$(input).attr('name', name);
1899+
$(input).attr('orig-name', originalName);
18981900
originalElements.push({
18991901
element: $(input),
19001902
name: originalName
@@ -1908,8 +1910,11 @@
19081910
this.options.submitHandler = function (form) {
19091911
originalElements.forEach(function (element) {
19101912
element.element.attr('name', element.name);
1913+
element.element.removeAttr('orig-name');
19111914
});
1912-
form.submit();
1915+
1916+
/* Call the originalSubmitHandler if it's a function */
1917+
typeof originalSubmitHandler === 'function' && originalSubmitHandler(form);
19131918
};
19141919
},
19151920

lib/web/mage/validation/validation.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,13 @@
4949
'validate-one-checkbox-required-by-name': [
5050
function (value, element, params) {
5151
var checkedCount = 0,
52+
selector,
5253
container;
5354

5455
if (element.type === 'checkbox') {
55-
$('[name="' + element.name + '"]').each(function () {
56+
/* If orig-name attribute is present, use it for validation. Else use name */
57+
selector = = element.getAttribute('orig-name') ? '[orig-name="' + element.getAttribute('orig-name') + '"]' : '[name="' + element.name + '"]';
58+
$(selector).each(function () {
5659
if ($(this).is(':checked')) {
5760
checkedCount += 1;
5861

0 commit comments

Comments
 (0)