validatorjs icon indicating copy to clipboard operation
validatorjs copied to clipboard

Bug with required_if & boolean still in 3.13.3

Open orditeck opened this issue 8 years ago • 1 comments

boolean on required_if (#132) seems to be fixed, nested object (#134) too, but the following code doesn't work. It passes the validation and shouldn't:

const myEvent = {
    datetimes: {
        recurring: true,
        recurring_frequency: null,
        recurring_interval: null,
        recurring_by_day: null,
        recurring_by_day_month: null
    }
};

const myRules = {
    datetimes: {
        recurring: ['required', 'boolean'],
        recurring_frequency: ['required_if:datetimes.recurring,true', 'in:daily,weekly,monthly'],
        recurring_interval: ['required_if:datetimes.recurring,true', 'between:1,6'],
        recurring_by_day: ['required_if:datetimes.recurring,true', 'in:MO,TU,WE,TH,FR,SA,SU'],
        recurring_by_day_month: ['required_if:datetimes.recurring,true', 'between:1,31'],
    },
};

let myValidation = new Validator(myEvent, myRules);
if(!myValidation.passes()){
    console.log(myValidation.errors);
}

Changing recurring: true to recurring: 'true' fixes the issue.

I'm using version 3.13.3.

orditeck avatar Aug 16 '17 18:08 orditeck

I think it's the same with integers, 'fieldB' => 'integer|required_if:fieldA,0' treats 0 as string, so the check

if (this.validator._objectPath(this.validator.input, req[0]) === req[1]) {

fails, as the req[1] is string, and the field's value is integer.

vlascik avatar Sep 25 '17 01:09 vlascik