Closed pixelpaulaus closed 5 years ago
Yup coz in:18451,18367,18364
is interpreted as string. You have to use the rule
method here.
{
code: [
rule('required'),
rule('integer'),
rule('in', [18451,18367,18364])
]
}
hmmm, not sure that is possible in adonisjs :-(
shouldn't it see the interger requirement and match against integers?
Why you think it's not possible in Adonis?
sorry i could not find any example of writing in the rule method you mentioned. so i could rewrite...
const rules = { subject: 'required|string|max:200', department: 'required|integer|in:18451,18367,18364', service: 'integer', }
to be like...
const rules = { subject: 'required|string|max:200', department: code: [ rule('required'), rule('integer'), rule('in', [18451,18367,18364]) ], service: 'integer', }
You can use it as follows:
const { rule } = use('Validator')
thanks, but that is not very clear. are there any examples in the docs to do it this way?
const validation = await validate(request.post(), rules)
Indicative docs does talk about it https://indicative.adonisjs.com/docs/syntax-guide#_limitations
when validating an integer is one of...
required|integer|in:18451,18367,18364
It returns a fail as it is matching against a string. The submitted value is indeed a integer tho. validator:equals works, but not validator:In