terminal42 / contao-conditionalformfields

Display form fields conditionally in Contao Open Source CMS
MIT License
18 stars 13 forks source link

Checkboxen werden nicht unterstützt #91

Closed FrischBlau closed 2 months ago

FrischBlau commented 2 months ago

Hi,

Checkboxen werden in Version 3.11 nicht unterstützt (siehe auch https://github.com/terminal42/contao-conditionalformfields/issues/2#issuecomment-1834066056) In älteren Versionen ging das. Contao macht bei den Checkboxen aus dem Feldnamen "foo" -> 'name="foo[]"' Eine condition wie "foo == 'bar'" greift damit nicht und "foo[] == 'bar'" ist als Eingabe nicht möglich.

Schönen Nachmittag

fritzmg commented 2 months ago

Both foo == 'bar' and foo[] == 'bar would be wrong. foo is the correct variable name, but since in your case it is a checkbox with multiple options, it is an array of values, not single value.

You need to use

in_array('bar', foo)

Note: in_array (and in) are features of the ExpressionLanguage that are available by default in Symfony 6.4 (Contao 5). However, terminal42/contao-conditionalformfields also adds this functionality manually:

https://github.com/terminal42/contao-conditionalformfields/blob/d04822b99832a5e840cdb8d4c9a761bc901b0a8f/src/FormHandler.php#L41-L45