diff --git a/src/Oro/Bundle/FormBundle/Resources/public/js/app/views/editor/text-editor-view.js b/src/Oro/Bundle/FormBundle/Resources/public/js/app/views/editor/text-editor-view.js index 90c60fac231..7bb9bcfd715 100644 --- a/src/Oro/Bundle/FormBundle/Resources/public/js/app/views/editor/text-editor-view.js +++ b/src/Oro/Bundle/FormBundle/Resources/public/js/app/views/editor/text-editor-view.js @@ -164,7 +164,7 @@ define(function(require) { error.appendTo($(element).closest('.inline-editor-wrapper')); }, rules: { - value: this.getValidationRules() + value: $.validator.filterUnsupportedValidators(this.getValidationRules()) } }); if (this.options.value) { diff --git a/src/Oro/Bundle/FormBundle/Resources/public/js/extend/validate.js b/src/Oro/Bundle/FormBundle/Resources/public/js/extend/validate.js index febf9b5b84b..ac0b242215a 100644 --- a/src/Oro/Bundle/FormBundle/Resources/public/js/extend/validate.js +++ b/src/Oro/Bundle/FormBundle/Resources/public/js/extend/validate.js @@ -3,9 +3,10 @@ define([ 'underscore', 'orotranslation/js/translator', 'oroui/js/tools', + 'oroui/js/tools/logger', './../optional-validation-handler', 'jquery.validate' -], function($, _, __, tools, validationHandler) { +], function($, _, __, tools, logger, validationHandler) { 'use strict'; var console = window.console; @@ -355,4 +356,23 @@ define([ return this[0] && this[0].form && $.data(this[0].form, 'validator') && handler.apply(this, arguments); }); }); + + /** + * Filters unsupported validation rules from validator configuration object + * + * @param {Object} validationRules - validator configuration object + * @returns {Object} filtered validation rules + */ + $.validator.filterUnsupportedValidators = function(validationRules) { + var validationRulesCopy = $.extend(true, {}, validationRules); + for (var ruleName in validationRulesCopy) { + if (validationRulesCopy.hasOwnProperty(ruleName)) { + if (!_.isFunction($.validator.methods[ruleName])) { + logger.warn('Cannot find validator implementation for `{{rule}}`', {rule: ruleName}); + delete validationRulesCopy[ruleName]; + } + } + } + return validationRulesCopy; + }; }); diff --git a/src/Oro/Bundle/UIBundle/Resources/public/js/tools/logger.js b/src/Oro/Bundle/UIBundle/Resources/public/js/tools/logger.js new file mode 100644 index 00000000000..a8a06450117 --- /dev/null +++ b/src/Oro/Bundle/UIBundle/Resources/public/js/tools/logger.js @@ -0,0 +1,53 @@ +define(function(require) { + 'use strict'; + + var tools = require('oroui/js/tools'); + var _ = require('underscore'); + var console = window.console; + + return { + /** + * Shows warning, only in DEV mode + * + * ```javascript + * logger.warn('Value `{{value}}` is not valid', {value: 5}); + * ``` + * + * @param {String} message - message to warn + * @param {Object} variables - variables to replace in message text + */ + warn: function(message, variables) { + var tpl = _.template(message, { + interpolate: /\{\{([\s\S]+?)}}/g + }); + if (tools.debug) { + if (console && console.error) { + // error method is used as it prints stack trace + console.error('Warning: ' + tpl(variables || {})); + } else { + var error = new Error('Warning: ' + tpl(variables || {})); + setTimeout(function() { + throw error; + }, 0); + } + } + }, + + /** + * Throws exception with message + * + * ```javascript + * logger.error('Value `{{value}}` is not valid', {value: 5}); + * ``` + * + * @param {String} message - message for exception to throw + * @param {Object} variables - variables to replace + */ + error: function(message, variables) { + var tpl = _.template(message, { + interpolate: /{{([\s\S]+?)}}/g + }); + throw new Error(tpl(variables || {})); + } + }; +});