Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony form: disable "required" for a field from Twig

I'm trying to disable the frontend HTML5 validation for a filed in a form built in Symfony.

In Twig, i use this code:

{{ form_widget(form.email, {'attr': {'class': 'form-control input-lg','novalidate': 'novalidate}}) }}

but the field is still considered as required. What am I doing wrong?

like image 225
Aerendir Avatar asked Jun 13 '15 11:06

Aerendir


1 Answers

You can set that in your form type to disable the field validation.

->add('test', null, array(
    'required' => false
))

If you want to disable it for the whole field you can try something like this:

{{ form_start(form, { attr: {novalidate: 'novalidate'} }) }}
like image 132
René Höhle Avatar answered Sep 20 '22 03:09

René Höhle