エンティティにバインドされていないフォームを Symfony で作成しました。フォーム要素の 1 つは、一連のチェックボックスであるfieldtypesです。どのfieldtypeチェックボックスが表示されるかは、 searchbyフィールドの値によって異なります。各チェックボックスにクラスを追加して、後で追加する JavaScript の表示/非表示フックとして使用したいと考えています。しかし、私が見る限り、choicesフォーム要素では、クラス全体を適用することしかできません。
これが私のフォームの関連部分です:
$form = $this->createFormBuilder()
->add('searchby', 'choice', array(
'label' => 'browse.label.searchby',
'choices'=>array(
'name' => 'browse.searchby.name',
'location' => 'browse.searchby.location',
'classification' => 'browse.searchby.classification'
),
'required' => true,
'multiple' => false,
'expanded' => true,
))
->add('fieldtypes', 'choice', array(
'label' => 'browse.label.fieldtypes',
'choices' => array(
'extensionAttribute12' => 'person.label.position.fr',
'title' => 'person.label.position.eng',
'l' => 'person.label.city',
'st' => 'person.label.province',
'co' => 'person.label.country',
'givenname' => 'person.label.firstname',
'sn' => 'person.label.lastname',
'name' => 'person.label.fullname',
),
'required' => true,
'multiple' => true,
'expanded' => true
));
から作成されたラジオボタンにクラス「searchbyname」を追加したい場合$options['choices']['givenname'], $options['choices']['sn'], $options['choices']['name']
、どうすればよいですか?