validate.js icon indicating copy to clipboard operation
validate.js copied to clipboard

format function isnt being called

Open rajashekhargundeti opened this issue 8 years ago • 2 comments

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.

rajashekhargundeti avatar Dec 15 '16 14:12 rajashekhargundeti

:+1:

jars avatar Dec 07 '17 21:12 jars

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

ansman avatar Dec 11 '17 05:12 ansman