- /**
- * Validate single element.
- *
- * @param {Element} element
- * @param {Object} config
- * @returns {*}
- */
- $.validator.validateSingleElement = function (element, config) {
- var errors = {},
- valid = true,
- validateConfig = {
- errorElement: 'label',
- ignore: '.ignore-validate'
- },
- form, validator, classes, elementValue;
-
- $.extend(validateConfig, config);
- element = $(element).not(validateConfig.ignore);
-
- if (!element.length) {
- return true;
- }
-
- form = element.get(0).form;
- validator = form ? $(form).data('validator') : null;
-
- if (validator) {
- return validator.element(element.get(0));
- }
-
- classes = element.prop('class').split(' ');
- validator = element.parent().data('validator') ||
- $.mage.validation(validateConfig, element.parent()).validate;
-
- element.removeClass(validator.settings.errorClass);
- validator.toHide = validator.toShow;
- validator.hideErrors();
- validator.toShow = validator.toHide = $([]);
-
- $.each(classes, $.proxy(function (i, className) {
- elementValue = element.val();
-
- if (element.is(':checkbox') || element.is(':radio')) {
- elementValue = element.is(':checked') || null;
- }
-
- if (this.methods[className] && !this.methods[className](elementValue, element.get(0))) {
- valid = false;
- errors[element.get(0).name] = this.messages[className];
- validator.invalid[element.get(0).name] = true;
- validator.showErrors(errors);
-
- return valid;
- }
- }, this));
-
- return valid;
- };