@@ -192,10 +192,13 @@ public function testHandleCheckboxChanges()
192192 'choice_required_with_empty_preferred_choices ' => 'ok ' ,
193193 'choice_expanded ' => '' ,
194194 'choice_multiple ' => ['2 ' ],
195+ 'choice_multiple_disabled ' => [],
196+ 'choice_expanded_disabled ' => '' ,
195197 'select_multiple ' => ['2 ' ],
196198 'entity ' => (string ) $ id ,
197199 'checkbox ' => null ,
198200 'checkbox_checked ' => '1 ' ,
201+ 'checkbox_checked_disabled ' => null ,
199202 'file ' => '' ,
200203 'hidden ' => '' ,
201204 'complexType ' => [
@@ -294,6 +297,48 @@ public function testHandleCheckboxChanges()
294297 ;
295298 }
296299
300+ public function testDisabledChoicesAreNeverSubmitted ()
301+ {
302+ CategoryFixtureEntityFactory::createMany (5 );
303+
304+ $ mounted = $ this ->mountComponent (
305+ 'form_with_many_different_fields_type ' ,
306+ [
307+ 'initialData ' => [
308+ // "foo" (value 1) is disabled through "choice_attr"
309+ 'choice_multiple_disabled ' => [1 , 2 ],
310+ ],
311+ ]
312+ );
313+
314+ $ dehydratedProps = $ this ->dehydrateComponent ($ mounted )->getProps ();
315+
316+ // like a browser, the checked but disabled choice is not part of the
317+ // values that would be submitted
318+ $ this ->assertSame (['2 ' ], $ dehydratedProps ['form ' ]['choice_multiple_disabled ' ]);
319+
320+ // a model update must not resurrect the disabled value either
321+ $ crawler = $ this ->browser ()
322+ ->throwExceptions ()
323+ ->post ('/_components/form_with_many_different_fields_type ' , [
324+ 'body ' => [
325+ 'data ' => json_encode ([
326+ 'props ' => $ dehydratedProps ,
327+ 'updated ' => ['form ' => ['choice_multiple_disabled ' => []]],
328+ ]),
329+ ],
330+ ])
331+ ->assertSuccessful ()
332+ ->crawler ()
333+ ;
334+
335+ $ dehydratedProps = json_decode (
336+ $ crawler ->filter ('div ' )->first ()->attr ('data-live-props-value ' ),
337+ true
338+ );
339+ $ this ->assertSame ([], $ dehydratedProps ['form ' ]['choice_multiple_disabled ' ]);
340+ }
341+
297342 public function testLiveCollectionTypeAddButtonsByDefault ()
298343 {
299344 $ dehydrated = $ this ->dehydrateComponent ($ this ->mountComponent ('form_with_live_collection_type ' ))->getProps ();
0 commit comments