Friday, July 4, 2008

Custom validation and messages

Once again, Cruxade's validation library have been improved to allow cleaner code for custom validations and error message. The snippet below was taken from chrome://cruxade/content/validation.xul

var lv_oContainer = cruxade_ExtendContainer("container");
var lv_aValidator = [];
lv_aValidator["testdate"]={
_validate_ : "required :vCustomFunc",
_errmessage_: function(nErrCode){
if (nErrCode==10) return "Max Error number?";
return "custommessage";
},
CustomFunc:function(oItem,oSrc){
// return 0 if no error
return 10; // test case error
}
};
lv_aValidator["greetings"]={
_validate_ : "required typedigit",
_errmessage_:function(nErrCode){
if (nErrCode==2) return "Please give me a number.";
}
}
lv_oContainer.udf_bHookValidation(lv_aValidator);


Feel like hacking the code..?

The uda_validate options ":v" still works. ":m" is deprecated. Shall we carry on with the ":m" option? Tell me what you think.

:-)