After multiple Google searches (including reading many Stack Overflow questions and answers) and a few hours spent reading the Symfony source code (to no avail), I finally decided to create an account here and ask the community.
My problem is that a form field which is supposed to be optional is returning the standard NotBlank error message when not filled out, despite the fact that the underlying entity property does not have the NotBlank constraint - and in fact is set to allow null values:
/**
* @ORM\Column(type="integer", nullable=true)
* @Assert\Type("integer")
*/
protected $delay_actual;
Additionally, though significantly less seriously, I have to manually set it to not be required in the form type, despite the fact that I'm using guessing:
->add('delay_actual', null, [
'required' => false,
'label_format' => 'delay.delay_act'
])
The form is handled in an AJAX controller action without anything extra going on (i.e. every field is tied directly to the entity). The form is displayed like so in its own Twig template:
{{ form_start(form) }}
{{ form_end(form) }}
I've tried removing @Assert\Type("integer")
from the property but that didn't help. I've also tried adding @Assert\Blank()
just to see what effect it would have and it did prevent the NotBlank error, but obviously that's not a real solution.
Anyway, pretty weird that it should be such a pain to have a simple optional field in a form when using the Symfony platform. Anybody have any idea what I might be missing?
Update: This was eventually fixed by updating Symfony, proving for me that it was caused by a bug in the framework.