Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with optional date #2

Closed
bnadim opened this issue Nov 22, 2016 · 1 comment
Assignees
Labels
bug
Milestone

Comments

@bnadim
Copy link

@bnadim bnadim commented Nov 22, 2016

Context

  • node version: 6.9.1
  • joi version: 10.0.1 - extension 1.0.0
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce ?

Fields with format option become required even if they are written as optional

const BaseJoi = require('joi')
const Extension = require('joi-date-extensions')
const Joi = BaseJoi.extend(Extension)

const schema = Joi.object().required().keys({
    date: Joi.date().format('YYYY-MM-DD').optional()
});

const data = { }

Joi.validate(data, schema, { allowUnknown: true }, (err, validatedData) => {
    if (err) {
        console.log('Validation error : ', err)
    } else {
        console.log('Validation success')
    }
})

Which result you had ?

'"date" must be a string with one of the following formats YYYY-MM-DD'

What did you expect ?

Data should be a valid result

@Marsup Marsup added the bug label Nov 22, 2016
@Marsup Marsup self-assigned this Nov 22, 2016
@Marsup Marsup added this to the 1.0.1 milestone Nov 22, 2016
@Marsup Marsup closed this in df08465 Nov 22, 2016
@Marsup

This comment has been minimized.

Copy link
Member

@Marsup Marsup commented Nov 22, 2016

Thanks for the report, patch published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.