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

Problem with required field, when type is set #4

Open
weierophinney opened this issue Dec 31, 2019 · 3 comments
Open

Problem with required field, when type is set #4

weierophinney opened this issue Dec 31, 2019 · 3 comments

Comments

@weierophinney
Copy link
Contributor

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"}


Originally posted by @tasselchof at zfcampus/zf-content-validation#90

@weierophinney
Copy link
Contributor Author

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.


Originally posted by @Wilt at zfcampus/zf-content-validation#90 (comment)

@weierophinney
Copy link
Contributor Author

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

Here it is.


Originally posted by @tasselchof at zfcampus/zf-content-validation#90 (comment)

@weierophinney
Copy link
Contributor Author

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.


Originally posted by @Bombdog at zfcampus/zf-content-validation#90 (comment)

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

No branches or pull requests

1 participant