Limenius / Liform

PHP library to render Symfony Forms to JSON Schema

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Initial value for CheckboxType within form is 1/0 instead of true/false

kylemartin87 opened this issue · comments

Liform serializes CheckboxType type to 1/0 instead of true/false. Then when liform-react attempts to validate it, it fails because it wants a true or false. I found that making the following change within Serializer/Normalizer/FormViewNormalizer.php fixes it:

From:

        } else {
            return $object->vars['value'];
        }

To:

        } else {
            if (isset($object->vars['checked'])) {
                return $object->vars['checked'];
            }
            return $object->vars['value'];
        }

Is this the correct place to be fixing the error?

Thanks for spotting this. Yes, sure, I think so.

Maybe is it possible for users to work around this with some data transformer in the form, but I guess that doing this in the FormViewNormalizer makes the library more usable and gives less surprises.

Do you want to open a PR with this change? Otherwise I can do it myself.