validate.js
validate.js copied to clipboard
format function isnt being called
Hi,
I'm trying to use "datetime" validator. constraints are "datetime": {"format" : "YYYY/MM/DD hh:mm:ss"} Here are my parse and format functions:
_validate.extend(_validate.validators.datetime, {
parse: function(value, options) {
console.log("Parse Validations:%s, %s", value, JSON.stringify(options));
var strictMode = options.strictMode ? options.strictMode : true;
return options.format ? +moment.utc(value,options.format, strictMode) : +moment.utc(value, strictMode);
},
format: function(value, options) {
console.log("Format Validations:%s, %s", value, JSON.stringify(options));
var format = options.format ? options.format : (options.dateOnly ? "YYYY-MM-DD" : "YYYY-MM-DD hh:mm:ss");
return moment.utc(value).format(format);
}
});
I notice that only Parse function is getting called, but not format function.
I looked at datetime validator in your code, but i couldn't find the call to format function. I just notice the Parse Validations in the console log, but not format's. Could you please elaborate on how to make sure that format function is called.
:+1:
format is called from multiple places, it is called when generating error messages for the user:
https://github.com/ansman/validate.js/blob/master/validate.js#L955