vendor/assets/javascripts/webshims/shims/combos/30.js in webshims-rails-1.12.2 vs vendor/assets/javascripts/webshims/shims/combos/30.js in webshims-rails-1.12.3

- old
+ new

@@ -1375,10 +1375,13 @@ } if(typeof message == 'object'){ message = message.defaultMessage; } + if(webshims.replaceValidationplaceholder){ + message = webshims.replaceValidationplaceholder(elem, message); + } return message || ''; }; $.fn.getErrorMessage = function(key){ var message = ''; @@ -1515,51 +1518,58 @@ if(message && typeof message !== 'string'){ message = message[ $.prop(elem, 'type') ] || message[ (elem.nodeName || '').toLowerCase() ] || message[ 'defaultMessage' ]; } return message || ''; }; + var lReg = /</g; + var gReg = />/g; var valueVals = { value: 1, min: 1, max: 1 }; - - webshims.createValidationMessage = function(elem, name){ - var widget; - var type = $.prop(elem, 'type'); - var message = getMessageFromObj(currentValidationMessage[name], elem); - if(!message && name == 'badInput'){ - message = getMessageFromObj(currentValidationMessage.typeMismatch, elem); - } - if(!message && name == 'typeMismatch'){ - message = getMessageFromObj(currentValidationMessage.badInput, elem); - } - if(!message){ - message = getMessageFromObj(validityMessages[''][name], elem) || $.prop(elem, 'validationMessage'); - webshims.info('could not find errormessage for: '+ name +' / '+ type +'. in language: '+webshims.activeLang()); - } - if(message){ + + webshims.replaceValidationplaceholder = function(elem, message, name){ + var type, widget; + if(message && message.indexOf('{%') != -1){ ['value', 'min', 'max', 'title', 'maxlength', 'minlength', 'label'].forEach(function(attr){ if(message.indexOf('{%'+attr) === -1){return;} var val = ((attr == 'label') ? $.trim($('label[for="'+ elem.id +'"]', elem.form).text()).replace(/\*$|:$/, '') : $.prop(elem, attr)) || ''; if(name == 'patternMismatch' && attr == 'title' && !val){ webshims.error('no title for patternMismatch provided. Always add a title attribute.'); } if(valueVals[attr]){ if(!widget){ - widget = $(elem).getShadowElement().data('wsWidget'+type); + widget = $(elem).getShadowElement().data('wsWidget'+ (type = $.prop(elem, 'type'))); } if(widget && widget.formatValue){ val = widget.formatValue(val, false); } } - message = message.replace('{%'+ attr +'}', val); + message = message.replace('{%'+ attr +'}', val.replace(lReg, '&lt;').replace(gReg, '&gt;')); if('value' == attr){ message = message.replace('{%valueLen}', val.length); } - + }); } + return message; + }; + + webshims.createValidationMessage = function(elem, name){ + + var message = getMessageFromObj(currentValidationMessage[name], elem); + if(!message && name == 'badInput'){ + message = getMessageFromObj(currentValidationMessage.typeMismatch, elem); + } + if(!message && name == 'typeMismatch'){ + message = getMessageFromObj(currentValidationMessage.badInput, elem); + } + if(!message){ + message = getMessageFromObj(validityMessages[''][name], elem) || $.prop(elem, 'validationMessage'); + webshims.info('could not find errormessage for: '+ name +' / '+ $.prop(elem, 'type') +'. in language: '+webshims.activeLang()); + } + message = webshims.replaceValidationplaceholder(elem, message, name); return message || ''; }; \ No newline at end of file