Example showing how a dependant group (aka sub form) might be attached to a radio.
6{
7
9 $ui =
$DIC->ui()->factory();
10 $renderer =
$DIC->ui()->renderer();
11 $request =
$DIC->http()->request();
12
13
14 $group1 = $ui->input()->field()->group(
15 [
16 "field_1_1" => $ui->input()->field()->text("Item 1.1", "Just some field"),
17 "field_1_2" => $ui->input()->field()->text("Item 1.2", "Just some other field")
18 ],
19 "Switchable Group number one (with numeric key)"
20 );
21 $group2 = $ui->input()->field()->group(
22 [
23 "field_2_1" => $ui->input()->field()->text("Item 2", "Just another field")
24 ->withValue('some val')
25 ],
26 "Switchable Group number two"
27 );
28 $group3 = $ui->input()->field()->group([], 'No items in this group');
29
30
31 $sg = $ui->input()->field()->switchableGroup(
32 [
33 "1" => $group1,
34 "g2" => $group2,
35 "g3" => $group3
36 ],
37 "Pick One",
38 "...or the other"
39 );
40
41 $form = $ui->input()->container()->form()->standard(
42 '#',
43 [
44 'switchable_group' => $sg,
45
46
47 'switchable_group2' => $sg->withValue("g2")
48 ->withLabel("Again, Pick One")
49 ->withByline("... or the other.
50 Note, the second option is selected by default here.")
51 ]
52 );
53
54
55 if ($request->getMethod() == "POST") {
56 $form = $form->withRequest($request);
58 } else {
60 }
61
62
63 return
64 "<pre>" . print_r(
$result,
true) .
"</pre><br/>" .
65 $renderer->render($form);
66}