Skip to content

Commit 2d11f19

Browse files
committed
CRLF fix
1 parent b146164 commit 2d11f19

File tree

1 file changed

+9
-6
lines changed
  • projects/spring-modules-validation/spring-modules-validation-base/src/main/resources/META-INF

1 file changed

+9
-6
lines changed

projects/spring-modules-validation/spring-modules-validation-base/src/main/resources/META-INF/valang_codebase.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ var ValangValidator = function(name, installSelfWithForm, rules, validateOnSubmi
3535
ValangValidator.Logger.push('recieved ' + e.type);
3636

3737
var delay = 5; //yield time
38-
if(thisValidator.doValidation) clearTimeout(thisValidator.doValidation);
3938

4039
//don't fire for some key presses:
4140
if(e.type == "keyup" || e.type == "keydown" ){
@@ -54,6 +53,7 @@ var ValangValidator = function(name, installSelfWithForm, rules, validateOnSubmi
5453
}
5554
delay = 250;
5655
}
56+
if(thisValidator.doValidation) clearTimeout(thisValidator.doValidation);
5757

5858
var self = this;
5959
var doValidate = function() {
@@ -64,7 +64,7 @@ var ValangValidator = function(name, installSelfWithForm, rules, validateOnSubmi
6464
thisValidator.doValidation = setTimeout(function(){doValidate();}, delay);
6565
};
6666

67-
this.addRules(rules);
67+
this.addRules(rules, false);
6868

6969
if (installSelfWithForm) {
7070
this._installSelfWithForm(validateOnSubmit);
@@ -77,7 +77,7 @@ ValangValidator.prototype = {
7777
emptyErrorHTML: '',
7878
classRuleFieldName: "valang-global-rules", // to match CommandObjectToValangConverter.CLASS_RULENAME
7979

80-
addRules: function(newRules){
80+
addRules: function(newRules, addFirst){
8181
//create grouped rules by field
8282
for (var i = 0; i < newRules.length; i++) {
8383
var ruleField = newRules[i].field;
@@ -87,8 +87,9 @@ ValangValidator.prototype = {
8787
this.groupedRules[ruleField] = new Array();
8888
fieldArray = this.groupedRules[ruleField];
8989
}
90-
fieldArray.push(newRules[i]);
91-
90+
91+
fieldArray[addFirst ? "unshift":"push"](newRules[i]);
92+
9293
var fields = this.form.getFieldsWithName(ruleField);
9394
for(field in fields){
9495
this.addEventHandler(fields[field]);
@@ -603,8 +604,10 @@ ValangValidator.Rule.prototype = {
603604
},
604605

605606
// Unary Operators
607+
606608
lengthOf: function(value) {
607-
return (value != null) ? value.length : 0;
609+
// only count a CRLF as 1 char: makes LF/CRLF/CR count consistant across OS and browsers.
610+
return (value != null) ? value.replace(/\r\n/g,"\n").length : 0;
608611
},
609612
lowerCase: function(value) {
610613
return (value != null) ? value.toLowerCase(): null;

0 commit comments

Comments
 (0)