Answer the question
In order to leave comments, you need to log in
How to group select items in Symfony form builder?
You need to make a select by the districts of Nizhny Novgorod and the region, dividing them into groups, like this:
<select id="offer_add_district" name="offer_add[district]">
<optgroup label="Нижний Новгород">
<option value="1">Автозаводский</option>
<option value="2">Канавинский</option>
<option value="3">Ленинский</option>
<option value="4">Московский</option>
<option value="5">Нижегородский</option>
</optgroup>
<optgroup label="Нижегородская обл.">
<option value="9">Ардатовский</option>
<option value="10">Арзамасский</option>
<option value="11">Балахнинский</option>
<option value="12">Богородский</option>
</optgroup>
</select>
$builder->add('district', null, ['group_by' => 'center']);
Answer the question
In order to leave comments, you need to log in
// Entity
class District
{
/**
* @ORM\Colimn...
*/
private $center;
/**
* @var string
*/
private $groupName;
public function getGroupName()
{
return $this->getCenter() ? 'Center' : 'Region';
}
}
// ...
$builder->add('district', null, ['group_by' => 'groupName']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question