laminas / laminas-form

Validate and display simple and complex forms, casting forms to business objects and vice versa
https://docs.laminas.dev/laminas-form/
BSD 3-Clause "New" or "Revised" License
80 stars 52 forks source link

FormMultiCheckbox doesn't render zero as hidden element #241

Closed rieschl closed 11 months ago

rieschl commented 11 months ago

Bug Report

Q A
Version(s) 3.13.0

Summary

When the unchecked value of a MultiCheckbox or Radio element is 0 and useHiddenElement is turned on, the FormMultiCheckbox helper renderes an empty string for the hidden element instead of 0.

Current behavior

The FormMultiCheckbox helper uses a ternary operator to check if the uncheckedValue of the element is falsy and then uses its own uncheckedValue. This results in ignoring a '0' as default unchecked value of the element because the ternary interprets '0' as false.

How to reproduce

Create a Radio element and enable useHiddenElement with a uncheckedValue of '0'.

Expected behavior

The value of the hidden element should be 0.

I'm not sure if the bugfix (PR with failing test for now #242) introduces a new, unexpected behavior for some consumers of this package?

Slamdunk commented 11 months ago

Thank you for reporting the bug with a failing test :+1:

rieschl commented 11 months ago

Thank you for reporting the bug with a failing test 👍

I'm not sure I would have taken that route to fix the bug but thanks for the quick fix! 🙂