Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force a field to not be required

Tags:

I am using Symfony2 and FOSUserBundle.

Just as detailed in the documentation, I have overridden and created a "name" property in the User entity.

I do all necessary and finally get that field to be shown in the form view.

The thing is: when I go form_widget(form.name) and the input html tag is generated, a required="required" property is generated within it. And that causes the engine to red the input when the field is not filled in.

How do I do to tell the Symfony2 not to make that field mandatory? I guess that it has to be here:

        parent::buildForm($builder, $options);      // add your custom field     $builder->add('name', 'text', array('label' => 'form.name'));     $builder->remove('username'); 

or here:

    /**  * @ORM\Column(type="string", length="255")  *  * @Assert\MinLength(limit="0", message="The name is too short.", groups={"Registration", "Profile"})  * @Assert\MaxLength(limit="255", message="The name is too long.", groups={"Registration", "Profile"})  */ private $name; 
like image 562
ElPiter Avatar asked Aug 08 '12 15:08

ElPiter


People also ask

How do you make a field not required?

Steps - Go to setup - click object manager - find and choose contact - click fields and relationships - click the drop-down (extreme left side of the row) - click edit - Scroll down the page - In general options, uncheck 'Always require a value in this field in order to save a record' - click save.

How do you set a field as required?

Select the field that you want to require always has a value. In the Field Properties pane, on the General tab, set the Required property to Yes.

When one field is filled other fields must be required?

if one field in the form is filled,all other fields must be filled or if none of the fields are filled then no need of checking validations. Iam using a method focus to add validations. once selecting a field,all fields are required validation executing.


1 Answers

$builder->add('name', 'text', array('label' => 'form.name','required' => false)); 
like image 85
Carlos Granados Avatar answered Sep 19 '22 08:09

Carlos Granados