aurelia / validatejs

Enables expressive validation using decorators and/or a fluent API.
MIT License
22 stars 23 forks source link

How to define and use Date() or DateTime() #96

Closed huw489 closed 8 years ago

huw489 commented 8 years ago

Hi. I notice these are commented out in the samples.

Looking at the documentation at http://validatejs.org/ and I found some example code:

// Before using it we must add the parse and format functions
// Here is a sample implementation using moment.js

validate.extend(validate.validators.datetime, {
// The value is guaranteed not to be null or undefined but otherwise it
// could be anything.
parse: function(value, options) {
return +moment.utc(value);
},
// Input is a unix timestamp
format: function(value, options) {
var format = options.dateOnly ? "YYYY-MM-DD" : "YYYY-MM-DD hh:mm:ss";
return moment.utc(value).format(format);
}
});

What i'm struggling with is where do I add this type of code in Aurelia? thanks in advance.

y2k4life commented 8 years ago

I was chatting on gitter with @MaximBalaganskiy about an unrelated issue, but the solution might be the same. Not a pretty one but a solution. That was to include validatjs as part of your project. If you look here https://gitter.im/aurelia/validation?at=576a1bdb2554bbe049ba5d36 and scroll up you will see a discussion about another issue, but I see the solution might be the same. This is also being discussed over here, https://github.com/aurelia/validation/issues/260 although this is the place for it, because this is an aurelia-validatejs issue not a aurelia-validation issue. You would need to do what is mentioned in the gitter discussion or wait for some method in aurelia-validatejs to setup these methods.

ashanvabs commented 8 years ago

+1

jdanyow commented 8 years ago

docs show how to create custom rules now