UPDATE-RATE

Die Test-Installation wird aktuell zwischen 8:00 und 18:00 Uhr stündlich zur vollen Stunde aktualisiert.

Alles neu macht der Mai

ILIAS 9 ist da! Alle Infos zu den Highlights der neuen Version gibt es hier!

Documentation

Kitchen Sink documentation of style: 'Delos' of skin: 'ILIAS'

Switchable Group

Description

Purpose
A switchable group is a collection of groups that makes the user decide which group he wants to fill with further input.
Composition
A switchable group is composed of radiobuttons that bear the label and the byline of the according group and the inputs contained in that group in a way to make them visually belong to the radio group.
Effect
If a radiobutton is selected, the according inputs are revealed and the other groups are hidden.

Rules

Usage
  1. There MUST NOT be a nesting of more than one optional and/or switchable group. The only exception to this rule is the required quantification of a subsetting by a date or number. These exceptions MUST individually accepted by the Jour Fixe.

Example 1: Base

No result yet.

* Required
Just some field
Just some other field
a date
Just another field
with byline
but a byline
...or the other
Just some field
Just some other field
a date
Just another field
with byline
but a byline
...or the other
Just some field
Just some other field
a date
Just another field
with byline
but a byline
... or the other. Second option is selected by default here.
<?php
 
declare(strict_types=1);
 
namespace ILIAS\UI\examples\Input\Field\SwitchableGroup;
 
/**
 * Example showing how a dependant group (aka sub form) might be attached to a radio.
 */
function base()
{
    //Step 0: Declare dependencies
    global $DIC;
    $ui = $DIC->ui()->factory();
    $renderer = $DIC->ui()->renderer();
    $request = $DIC->http()->request();
    $data = new \ILIAS\Data\Factory();
 
    //Step 1: Define the groups (with their fields and a label each)
    $group1 = $ui->input()->field()->group(
        [
            "field_1_1" => $ui->input()->field()->text("Item 1.1", "Just some field"),
            "field_1_2" => $ui->input()->field()->text("Item 1.2", "Just some other field"),
            "field_1_3" => $ui->input()->field()->datetime("Item 1.3", "a date")->withFormat($data->dateFormat()->germanShort())
        ],
        "Switchable Group number one (with numeric key)"
    );
    $group2 = $ui->input()->field()->group(
        [
            "field_2_1" => $ui->input()->field()->text("Item 2", "Just another field")
                ->withValue('some val')
        ],
        "Switchable Group number two",
        "with byline"
    );
    $group3 = $ui->input()->field()->group([], 'No items in this group', 'but a byline');
 
    //Step 2: Switchable Group - one or the other:
    $sg = $ui->input()->field()->switchableGroup(
        [
            "1" => $group1,
            "g2" => $group2,
            "g3" => $group3
        ],
        "Pick One",
        "...or the other"
    );
 
    $form = $ui->input()->container()->form()->standard(
        '#',
        [
            'switchable_group' => $sg,
            'switchable_group_required' => $sg->withRequired(true),
            'switchable_group_preset' => $sg->withValue("g2")
                                      ->withLabel("Again, Pick One")
                                      ->withByline("... or the other. 
                                      Second option is selected by default here.")
        ]
    );
 
    //Step 3: implement some form data processing.
    if ($request->getMethod() == "POST") {
        $form = $form->withRequest($request);
        $result = $form->getData();
    } else {
        $result = "No result yet.";
    }
 
    //Step 4: Render.
    return
        "<pre>" . htmlspecialchars(print_r($result, true), ENT_QUOTES) . "</pre><br/>" .
        $renderer->render($form);
}
 

Example 2: With disabled

Just some field
Just some field
nothing to pick here.
<?php
 
declare(strict_types=1);
 
namespace ILIAS\UI\examples\Input\Field\SwitchableGroup;
 
function with_disabled()
{
    global $DIC;
    $ui = $DIC->ui()->factory();
    $renderer = $DIC->ui()->renderer();
    $request = $DIC->http()->request();
    $data = new \ILIAS\Data\Factory();
 
    $group1 = $ui->input()->field()->group([$ui->input()->field()->text("Item 1", "Just some field")], "Group 1");
    $group2 = $ui->input()->field()->group([$ui->input()->field()->text("Item 2", "Just some field")], "Group 2");
 
    $sg = $ui->input()->field()->switchableGroup(
        [$group1,$group2],
        "Disabled Switchable Group",
        "nothing to pick here."
    )
    ->withDisabled(true);
 
    return $renderer->render($sg);
}
 

Relations

Parents
  1. UIComponent
  2. Input
  3. Field