From 374f3dd5bee76e5070926240659a5229c1b1d3e1 Mon Sep 17 00:00:00 2001 From: Matthew Wire Date: Fri, 7 Feb 2020 15:35:46 +0000 Subject: [PATCH] Fix implementation of jQuery.validate so that it actually uses the CRM settings, validates select2 fields and uses Civi/bootstrap classes for errors --- js/Common.js | 8 ++++---- templates/CRM/common/l10n.js.tpl | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/js/Common.js b/js/Common.js index 47c6e48b18e0..7a7cb9c0c917 100644 --- a/js/Common.js +++ b/js/Common.js @@ -842,9 +842,9 @@ if (!CRM.vars) CRM.vars = {}; */ $.fn.crmValidate = function(params) { return $(this).each(function () { - var that = this, - settings = $.extend({}, CRM.validate._defaults, CRM.validate.params); - $(this).validate(settings); + var validator = $(this).validate(); + var that = this; + validator.settings = $.extend({}, validator.settings, CRM.validate._defaults, CRM.validate.params); // Call any post-initialization callbacks if (CRM.validate.functions && CRM.validate.functions.length) { $.each(CRM.validate.functions, function(i, func) { @@ -1615,7 +1615,7 @@ if (!CRM.vars) CRM.vars = {}; return String(string).replace(/[&<>"'`=\/]/g, function fromEntityMap (s) { return entityMap[s]; }); - } + }; // CVE-2015-9251 - Prevent auto-execution of scripts when no explicit dataType was provided $.ajaxPrefilter(function(s) { diff --git a/templates/CRM/common/l10n.js.tpl b/templates/CRM/common/l10n.js.tpl index 74777751aec8..c76d15de0980 100644 --- a/templates/CRM/common/l10n.js.tpl +++ b/templates/CRM/common/l10n.js.tpl @@ -91,10 +91,9 @@ {literal} var params = { - errorClass: 'crm-inline-error', + errorClass: 'error alert-danger', messages: {}, - // TODO: remove after resolution of https://github.com/jzaefferer/jquery-validation/pull/1261 - ignore: ":hidden, [readonly]" + ignore: ".select2-offscreen, [readonly], :hidden:not(.crm-select2)" }; // use civicrm notifications when there are errors