Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Problem with required field, when type is set #90

Open
tasselchof opened this issue Apr 29, 2017 · 4 comments
Open

Problem with required field, when type is set #90

tasselchof opened this issue Apr 29, 2017 · 4 comments

Comments

@tasselchof
Copy link

tasselchof commented Apr 29, 2017

Hello!

Found such a case - if field is not set to required, but value is set to false:

[ 'required' => false, 'validators' => [], 'filters' => [], 'name' => 'debug', 'field_type' => 'boolean', ]

On request like this:

{"debug":false}

It will give an error:

{"validation_messages":{"debug":{"isEmpty":"Value is required and can't be empty"},"type":"http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html","title":"Unprocessable Entity","status":422,"detail":"Failed Validation"}

@Wilt
Copy link

Wilt commented May 2, 2017

Can you show the full input-filter configuration? I am almost certain the problem lies somewhere else. If this is really a bug then it should be reported at the correct repository: zendframework/zend-inputfilter.

@tasselchof
Copy link
Author

0 => [
                'required' => false,
                'validators' => [],
                'filters' => [],
                'name' => 'debug',
                'description' => 'Output debug information.',
            ],

Here it is.

@Bombdog
Copy link

Bombdog commented Nov 23, 2017

I have the exact same problem with an identical setup. If you pass boolean true then it's fine. If you don't set the element at all, it's fine (not required after all). But boolean false always triggers {"isEmpty":"Value is required and can't be empty"}. Seems the easiest way around this is to add 'allow_empty' => true to your configuration and condition your data accordingly at the other end. Probably just assume if it aint a boolean true then it's false.

@weierophinney
Copy link
Member

This repository has been closed and moved to laminas-api-tools/api-tools-content-validation; a new issue has been opened at laminas-api-tools/api-tools-content-validation#4.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants