How to set default form required state (and override in builder) in Symfony 3?

Viewed 2211

I'm trying to build a form and have the default 'required' state set to false, and then have the form build configuration override that, setting some to true.

If I add no configurationOptions, the fields default to 'required' as true, and I can override them with specific configurations.

However, if I add:

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefault('required', false);
}

I can't override that in the specific config (this does not make required true):

->add('name',TextType::class, array(
    'required' => true,
    'constraints' => array(new Length(array('min' => 3)))
))

Is there a way to do this, or must I always set no default and specify each config?

2 Answers
Related