Hi everybody,
I´m not only new to Neos and this forum but also kind of getting back into “some coding” after quite some years off it. So, please bear with my, I will try my best to not proof that “there are no dump questions” statement wrong
As a learning objective, I set myself to re-built a form that incorporates simple depedencies on checkboxes (at least one CB has to be checked) as well as connecting to an external API to send the data, to name a few and those in particular where I´m stuck.
So, I quickly ended up in the Demo package´s Contact form, adding a custom action for the external API call (which works, although propably not the Neos way but that´s for another post if I can´t figure it out myself) and the very basic task to make sure, the checkbox sections of the form behave as expected.
But here, I seem to be hard stuck as I can´t figure out how to do this. Meanwhile, I´m actually not even sure about the path I´m trying to take is right.
So, I thought, this clearly is a task for a validator. So, I´ve built a structure like this inside the fusion:
renderer = Neos.Fusion.Form:Runtime.RuntimeForm {
namespace = 'contact'
process {
content = afx`
<fieldset>
... some input fields like name, ...
</fieldset>
<fieldset>
<legend>Please select the most appropriate description(s)</legend>
<Neos.Fusion.Form:FieldContainer field.name="appropriate-description" field.multiple={true}>
<legend class="text-1xl">Legend 1</legend>
<Neos.Fusion.Form:Checkbox field.name="case-1" />
<legend class="text-1xl">Legend 2</legend>
<Neos.Fusion.Form:Checkbox field.name="case-2" />
<legend class="text-1xl">Legend 3</legend>
<Neos.Fusion.Form:Checkbox field.name="case-3" />
<legend class="text-1xl">Legend 4</legend>
<Neos.Fusion.Form:Checkbox field.name="case-4" />
<legend class="text-1xl">Legend 5</legend>
<Neos.Fusion.Form:Checkbox field.name="case-5" />
<legend class="text-1xl">Legend 6</legend>
<Neos.Fusion.Form:Checkbox field.name="case-6" />
<legend class="text-1xl">Legend 7</legend>
<Neos.Fusion.Form:Checkbox field.name="case-7" />
</Neos.Fusion.Form:FieldContainer>
</fieldset>
`
footer = afx`
<button type="submit">Submit</button>
`
schema {
...
appropriate-description = ${Form.Schema.array().isRequired().validator('Neos\Demo\Form\Runtime\Validation\Validator\FieldsetAppropiatedescriptionValidator')}
...
}
}
....
I hoped for the FieldContainer´s name/id to become an array with all the checkbox child nodes in there but it isn´t. All I get in the FieldsetAppropiatedescriptionValidator isValid function is an empty array like so:
Here´s the very basic FieldsetAppropiatedescriptionValidator class:
<?php
declare(strict_types=1);
use Neos\Flow\Validation\Validator\AbstractValidator;
class FieldsetAppropiatedescriptionValidator extends AbstractValidator
{
protected function isValid($value) {
$this->addError('<pre>'.var_export($value, true).'</pre>', 1234567890);
}
}
Also, when I try to validate a single checkbox as a boolean, it always shows true, regardless of the actual status of the checkbox.
So, I´m obviuosly doing something majorly wrong. All documentation I found is either not tackling those tasks or still beyond me to understand to be honest. So, I got even more confused by reading more over the last couple of days.
In this forum, I only found an old post (Form e-mail-finisher does not work for multiple checkbox-values) using fluid templates by naming all checboxes the same and setting all of them to multiple={true} but yeah, that´s fluid and also the fields need to have uinique names.
So, can somebody please point me in the right direction? Where am I taking the wrong path? Maybe, point me to a bunch of docu that I simply need to fully understand to solve my task?
Thank you very much
Andy