Tips

Add attribute to form field

To add attributes to a form field in Symfony, implement the following code. In this example, we add the 'rows' attribute, but of course, rows can be replaced by any other attribute.

Example code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
 * @var string
 * @ODMString
 * @TypeField(
 *      type="textarea",
 *      options={
 *          "attr"={
 *              "rows" = 10
 *          }
 *      }
 * )
 * @AssertNotBlank()
 */
protected $comment;