magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.57k stars 9.32k forks source link

mage.validation widget errorPlacement function not inside options so never gets loaded #39381

Closed phes71 closed 1 week ago

phes71 commented 1 week ago

Preconditions and environment

errorPlacement function should be inside options.

Steps to reproduce

error on grouped product pages click add to cart without any options selected, and the validation error message is displayed on every option instead of inside div with id #validation-message-box

Expected result

validation error should be in div id #validation-message-box

Actual result

validation error shown in every grouped option qty

Additional information

fix by moving errorPlacement function inside options as below

$.widget('mage.validation', $.mage.validation, { options: { radioCheckboxClosest: 'ul, ol',

    /**
     * @param {*} error
     * @param {HTMLElement} element
     */
    errorPlacement: function (error, element) {
        var messageBox,
            dataValidate;

        if ($(element).hasClass('datetime-picker')) {
            element = $(element).parent();

            if (element.parent().find('.mage-error').length) {
                return;
            }
        }

        if (element.attr('data-errors-message-box')) {
            messageBox = $(element.attr('data-errors-message-box'));
            messageBox.html(error);

            return;
        }

        dataValidate = element.attr('data-validate');

        if (dataValidate && dataValidate.indexOf('validate-one-checkbox-required-by-name') > 0) {
            error.appendTo('#links-advice-container');
        } else if (element.is(':radio, :checkbox')) {
            element.closest(this.radioCheckboxClosest).after(error);
        } else {
            element.after(error);
        }
    }},

Release note

No response

Triage and priority

m2-assistant[bot] commented 1 week ago

Hi @phes71. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce.

m2-assistant[bot] commented 1 week ago

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

phes71 commented 1 week ago

this will fix it https://github.com/magento/magento2/commit/95fd74f356652eb19274bf20815893649fafba72

phes71 commented 1 week ago

Issue: Confirmed

engcom-Bravo commented 1 week ago

Hi @phes71,

Thanks for your reporting and collaboration.

Similar issue has been Confirmed here https://github.com/magento/magento2/issues/39347

Hence we are closing this as duplicate.

Thanks.