Skip to content

Commit

Permalink
Merge commit 'ef714aee69ff6042a252a4c1eb93e29326615b24' into maintena…
Browse files Browse the repository at this point in the history
…nce/crm-enterprise-1.11
  • Loading branch information
mccar committed Jul 22, 2016
2 parents a516197 + ef714ae commit 8dea5f5
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
22 changes: 21 additions & 1 deletion src/Oro/Bundle/FormBundle/Resources/public/js/extend/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
});
53 changes: 53 additions & 0 deletions src/Oro/Bundle/UIBundle/Resources/public/js/tools/logger.js
Original file line number Diff line number Diff line change
@@ -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 || {}));
}
};
});

0 comments on commit 8dea5f5

Please sign in to comment.