adopted-ember-addons / ember-validators

A collection of EmberJS validators
Other
24 stars 40 forks source link

Support moment object in date validator #58

Closed ondrejsevcik closed 6 years ago

ondrejsevcik commented 6 years ago

Hi, it would be nice to support moment/computed property in date validator. I have a scenario where some field date must be after another field's date. I guess this example explains it pretty well.

expirationDate: [
  validator('date', {
    // model.createdDate is momentjs object
    after: computed.alias('model.createdDate'),
    precision: 'day',
    message: "Expiration date can't be before creation date.",
  })
]

Do you know how to make it work with current date validator? Otherwise, I can provide PR.

offirgolan commented 6 years ago

PR is welcome! I think it makes a lot of sense to support moment objects.

ondrejsevcik commented 6 years ago

It seems it's working. I just used it wrong. I should not provide format option.