Skip to content

When passing boolean value as required & default passed value is false in API it is consider that as no value or undefined. #2

@th3hero

Description

@th3hero

Unable to validate false as a boolean value with required parameter.

Problem Overview.

I was trying to validate a false value in a boolean parameter condition was that the field is required & must be a boolean in types, but when the api is getting true as a value it is working fine but if it is getting a false value somehow it is not able to validate that as a boolean it is returning validation error that field is required but the value is available as false.

OBJECT PASSED

// API Values passed as an object.
{
    "two_factor_enabled": true,
    "mfa_enabled": false,
    "reference": "7eada554656d51fd98db34e418326f9a306ea37d951f2f8b55542dde14a4416edb6168f072c9d8cb22047c354b9c87acd18380cf3f2903f5785be9cdab4d4bac",
    "code": "123456"
}

Validation Error

// Validation Error I am getting in response.
{
    "success": false,
    "message": "Validation failed",
    "data": null,
    "errors": {
        "mfa_enabled": "mfa_enabled is required"
    }
}

Validation Rule

// Validation Rule we have at our backend.
const loginValidateSchema = {
    reference: 'required|min:1',
    code: 'required|digits:6',
    two_factor_enabled: 'required|boolean',
    mfa_enabled: 'required|boolean'
};

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions