Author: pyaschenko
Date: 2010-10-07 11:35:54 -0400 (Thu, 07 Oct 2010)
New Revision: 19490
Modified:
sandbox/trunk/prototypes/csv/validator/length.js
sandbox/trunk/prototypes/csv/validator/test.html
Log:
Modified: sandbox/trunk/prototypes/csv/validator/length.js
===================================================================
--- sandbox/trunk/prototypes/csv/validator/length.js 2010-10-07 14:35:15 UTC (rev 19489)
+++ sandbox/trunk/prototypes/csv/validator/length.js 2010-10-07 15:35:54 UTC (rev 19490)
@@ -11,22 +11,20 @@
$.extend(rf.csv, {
// Messages API
addMessage: function (messagesObject) {
- for (var id in messagesObject) {
- _messages[id] =
messagesObject[id].replace(RE_MESSAGE_PATTERN,"\n$1\n").split("\n");
- }
+ $.extend(_messages, messagesObject);
},
- getMessage: function(id, values) {
- var msgObject = _messages[id];
- var result="";
- if (msgObject) {
+ getMessage: function(customMessages, id, values) {
+ var message = (customMessages && customMessages[id]) || _messages[id] ||
"";
+ if (message) {
+ var msgObject =
message.replace(RE_MESSAGE_PATTERN,"\n$1\n").split("\n");
var value;
for (var i=1; i<msgObject.length; i+=2) {
value = values[msgObject[i]];
msgObject[i] = typeof value == "undefined" ? "" : value;
}
- result = msgObject.join('');
+ message = msgObject.join('');
}
- return result;
+ return message;
},
// Validators API
addValidator: function (validatorFunctions) {
@@ -56,7 +54,7 @@
break;
}
}
- !messageComponentsUpdated &&
alert("");//updateMessageComponents(messageElementIds, "");
+ !messageComponentsUpdated && alert("no message from
validators");//updateMessageComponents(messageElementIds, "");
},
addFormValidators: function (formId, callValidatorFunctions) {
@@ -70,9 +68,9 @@
return function (value, params) {
var result = "";
if (value.length<params.min) {
- result = rf.csv.getMessage('LengthValidator.MINIMUM', [params.min,value]);
+ result = rf.csv.getMessage(params.customMessages, 'LengthValidator.MINIMUM',
[params.min,value]);
} else if (value.length>params.max){
- result = rf.csv.getMessage('LengthValidator.MAXIMUM', [params.max,value]);
+ result = rf.csv.getMessage(params.customMessages, 'LengthValidator.MAXIMUM',
[params.max,value]);
}
return result;
}
Modified: sandbox/trunk/prototypes/csv/validator/test.html
===================================================================
--- sandbox/trunk/prototypes/csv/validator/test.html 2010-10-07 14:35:15 UTC (rev 19489)
+++ sandbox/trunk/prototypes/csv/validator/test.html 2010-10-07 15:35:54 UTC (rev 19490)
@@ -15,11 +15,12 @@
<form id="myForm">
<input id="myInput" type="text" value="aaa"/>
<input type="button" onclick="v();" value="validate
length"/>
+<input type="button"
onclick="v({'LengthValidator.MINIMUM':'CustomMessage: length of the {1}
is smaller then {0} chars', 'LengthValidator.MAXIMUM':'CustomMessage:
length of the {1} is bigger then {0} chars'});" value="validate length
(custom message)"/>
</form>
<script>
RichFaces.csv.addMessage({'LengthValidator.MINIMUM':'Hello, length of the
"{1}" is smaller then {0} chars',
'LengthValidator.MAXIMUM':'Hello, length of the "{1}" is bigger then
{0} chars'});
-var v = function () {
- RichFaces.csv.validate(null, 'myInput', {'length':{min:1, max:5}}, null,
null);
+var v = function (customMessages) {
+ RichFaces.csv.validate(null, 'myInput', {'length':{min:1, max:5,
customMessages:customMessages}}, null, null);
};
</script>
</body>