|
| 1 | +define([ |
| 2 | + 'jquery', |
| 3 | + 'jquery-ui-modules/widget' |
| 4 | +], function ($) { |
| 5 | + 'use strict'; |
| 6 | + var enhancedMageValidation = { |
| 7 | + /** |
| 8 | + * @param {*} error |
| 9 | + * @param {*} element |
| 10 | + */ |
| 11 | + options: { |
| 12 | + errorPlacement: function (error, element) { |
| 13 | + var errorPlacement = element, |
| 14 | + fieldWrapper,messageBox; |
| 15 | + |
| 16 | + // logic for date-picker error placement |
| 17 | + if (element.hasClass('_has-datepicker')) { |
| 18 | + errorPlacement = element.siblings('button'); |
| 19 | + } |
| 20 | + // logic for field wrapper |
| 21 | + fieldWrapper = element.closest('.addon'); |
| 22 | + |
| 23 | + if (fieldWrapper.length) { |
| 24 | + errorPlacement = fieldWrapper.after(error); |
| 25 | + } |
| 26 | + //logic for checkboxes/radio |
| 27 | + if (element.is(':checkbox') || element.is(':radio')) { |
| 28 | + errorPlacement = element.parents('.control').children().last(); |
| 29 | + |
| 30 | + //fallback if group does not have .control parent |
| 31 | + if (!errorPlacement.length) { |
| 32 | + errorPlacement = element.siblings('label').last(); |
| 33 | + } |
| 34 | + } |
| 35 | + if (element.attr('data-errors-msg-box')) { |
| 36 | + messageBox = $(element.attr('data-errors-msg-box')); |
| 37 | + messageBox.html(error); |
| 38 | + return; |
| 39 | + } |
| 40 | + //logic for control with tooltip |
| 41 | + if (element.siblings('.tooltip').length) { |
| 42 | + errorPlacement = element.siblings('.tooltip'); |
| 43 | + } |
| 44 | + //logic for select with tooltip in after element |
| 45 | + if (element.next().find('.tooltip').length) { |
| 46 | + errorPlacement = element.next(); |
| 47 | + } |
| 48 | + errorPlacement.after(error); |
| 49 | + } |
| 50 | + |
| 51 | + } |
| 52 | + } |
| 53 | + |
| 54 | + return function (mageValidation) { |
| 55 | + $.widget('mage.validation', mageValidation, enhancedMageValidation); |
| 56 | + return $.mage.validation; |
| 57 | + } |
| 58 | +}); |
0 commit comments