@@ -1178,4 +1178,55 @@ public function it_filter_and_mutate_fields_request_values()
11781178 $ this ->assertEquals ('TEST ' , $ this ->request ['test_field ' ]);
11791179 }
11801180
1181+ /** @test */
1182+ public function it_add_option_attributes_properly ()
1183+ {
1184+ $ config = $ this ->config ;
1185+
1186+ $ formHelper = new FormHelper ($ this ->view , $ this ->translator , $ config );
1187+ $ formBuilder = new FormBuilder ($ this ->app , $ formHelper , $ this ->eventDispatcher );
1188+
1189+ $ choices = ['en ' => 'English ' , 'fr ' => 'French ' , 'zh ' => 'Chinese ' ];
1190+ $ optionAttributes = ['zh ' => ['disabled ' => 'disabled ' ]];
1191+
1192+ $ form = $ formBuilder ->plain ()
1193+ ->add ('languages_select ' , 'select ' , [
1194+ 'choices ' => $ choices ,
1195+ 'option_attributes ' => $ optionAttributes
1196+ ])
1197+ ->add ('languages_choice_select ' , 'choice ' , [
1198+ 'choices ' => $ choices ,
1199+ 'option_attributes ' => $ optionAttributes ,
1200+ 'expanded ' => false ,
1201+ 'multiple ' => false
1202+ ])
1203+ ->add ('languages_choice_select_multiple ' , 'choice ' , [
1204+ 'choices ' => $ choices ,
1205+ 'option_attributes ' => $ optionAttributes ,
1206+ 'expanded ' => false ,
1207+ 'multiple ' => true
1208+ ])
1209+ ->add ('languages_choice_checkbox ' , 'choice ' , [
1210+ 'choices ' => $ choices ,
1211+ 'option_attributes ' => $ optionAttributes ,
1212+ 'expanded ' => true ,
1213+ 'multiple ' => true
1214+ ])
1215+ ->add ('languages_choice_radio ' , 'choice ' , [
1216+ 'choices ' => $ choices ,
1217+ 'option_attributes ' => $ optionAttributes ,
1218+ 'expanded ' => true ,
1219+ 'multiple ' => false
1220+ ]);
1221+
1222+ $ formView = $ form ->renderForm ();
1223+
1224+ $ this ->assertStringContainsString ('<option value="zh" disabled="disabled"> ' , $ formView );
1225+ $ this ->assertStringNotContainsString ('<option value="en" disabled="disabled"> ' , $ formView );
1226+ $ this ->assertStringNotContainsString ('<option value="fr" disabled="disabled"> ' , $ formView );
1227+ $ this ->assertStringContainsString ('<input id="languages_choice_checkbox_zh" disabled="disabled" name="languages_choice_checkbox[]" type="checkbox" value="zh"> ' , $ formView );
1228+ $ this ->assertStringNotContainsString ('<input id="languages_choice_checkbox_en" disabled="disabled" name="languages_choice_checkbox[]" type="checkbox" value="en"> ' , $ formView );
1229+ $ this ->assertStringContainsString ('<input id="languages_choice_radio_zh" disabled="disabled" name="languages_choice_radio" type="radio" value="zh"> ' , $ formView );
1230+ $ this ->assertStringNotContainsString ('<input id="languages_choice_radio_en" disabled="disabled" name="languages_choice_radio" type="radio" value="en"> ' , $ formView );
1231+ }
11811232}
0 commit comments