1

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.

willherzog
  • 61
  • 1
  • 9
  • Is there any inheritance going on (that might override the field)? – ccKep Jun 01 '17 at 23:09
  • check your profiler, on the failed post, it should show what constraint is causing the error, and where it is coming from. -> http://imgur.com/a/UL8Cv – Sam Janssens Jun 02 '17 at 07:11
  • Well the profiler doesn't work (keeps saying it has a 404 error), but by trying it in dev mode I just determined that _the bug is only happening in prod mode_. So does that tell you anything? Oh, and @ccKep - There is no inheritance going on. – willherzog Jun 02 '17 at 19:43
  • If it's only happening in prod mode you likely didn't clear the cache. `php bin/console cache:clear --env=prod --no-debug` – ccKep Jun 03 '17 at 10:05
  • No, I clear the cache regularly. – willherzog Jun 04 '17 at 18:27

0 Answers0