As the title suggests, I have a choice field (radio html input) in my form which must have a selection before the user is allowed to proceed.
I have tried adding the validation into my validation.yml
file in the bundle (throws an error saying that the field is not a valid entity field), and I have also tried the adding a validator directly in the form code, but received an Exception because the validator classes don't implement the FormValidatorInterface
(code is below).
$builder->addValidator(new CallbackValidator(function(FormInterface $form) {
if(!$form['has_subalbums']->getData())
{
$form->addError(new FormError('Please indicate sub albums'));
}
}));
What is the correct way to validate non-entity fields?