ILIAS  trunk Revision v11.0_alpha-2662-g519ff7d528f
ILIAS\UI\examples\Input\Field Namespace Reference

Namespaces

 Checkbox
 
 ColorSelect
 
 DateTime
 
 Duration
 
 File
 
 Group
 
 Hidden
 
 Image
 
 
 Markdown
 
 MultiSelect
 
 Numeric
 
 OptionalGroup
 
 Password
 
 Radio
 
 Rating
 
 Section
 
 Select
 
 SwitchableGroup
 
 Tag
 
 Text
 
 Textarea
 
 TreeMultiSelect
 
 TreeSelect
 
 Url
 

Functions

 with_dedicated_name ()
 

description: > Example showing an Input with an optional dedicated name which is used as NAME attribute on the rendered input. More...

 
 with_dedicated_name_and_path ()
 

description: > Example showing Inputs with dedicated names that are contained within a named group. More...

 
 with_required ()
 

description: > Example showing the use of the withRequired() method More...

 
 with_required_custom_constraint ()
 

description: > Example showing the use of the withRequired() method with a custom constraint that replaces the default requirement constraint. More...

 

Function Documentation

◆ with_dedicated_name()

ILIAS\UI\examples\Input\Field\with_dedicated_name ( )


description: > Example showing an Input with an optional dedicated name which is used as NAME attribute on the rendered input.

This option is available for all Input/Fields. Inputs without a dedicated name will get an auto-generated name. Please see the interface of withDedicatedName() for further details on naming.

expected output: >

ILIAS shows the rendered Component.

Definition at line 36 of file with_dedicated_name.php.

References $DIC, and $renderer.

37 {
38  global $DIC;
39  $ui = $DIC->ui()->factory();
40  $renderer = $DIC->ui()->renderer();
41 
42  $text_input = $ui->input()->field()
43  ->text("Username", "A username")
44  ->withDedicatedName('username');
45 
46  // Inputs with and without dedicated names can be mixed
47  $password_input = $ui->input()->field()
48  ->password("Password", "A secret password");
49 
50  $duration_input = $ui->input()->field()
51  ->duration("Valid from/to")
52  ->withDedicatedName('valid');
53 
54  $form = $ui->input()->container()->form()->standard("", [$text_input, $password_input, $duration_input]);
55  return $renderer->render($form);
56 }
$renderer
global $DIC
Definition: shib_login.php:26

◆ with_dedicated_name_and_path()

ILIAS\UI\examples\Input\Field\with_dedicated_name_and_path ( )


description: > Example showing Inputs with dedicated names that are contained within a named group.

The name of the group is added to the 'path' and included in the name of the sub-inputs.

expected output: >

ILIAS shows the rendered Component.

Definition at line 33 of file with_dedicated_name_and_path.php.

References $DIC, and $renderer.

34 {
35  global $DIC;
36  $ui = $DIC->ui()->factory();
37  $renderer = $DIC->ui()->renderer();
38 
39  $street = $ui->input()->field()
40  ->text("Street", "Street and No.")
41  ->withDedicatedName('street');
42 
43  $city = $ui->input()->field()
44  ->text("City")
45  ->withDedicatedName('city');
46 
47  // This creates inputs named 'address/street' and 'address/city'
48  $address = $ui->input()->field()
49  ->group([$street, $city], "Address")
50  ->withDedicatedName('address');
51 
52  $form = $ui->input()->container()->form()->standard("", [$address]);
53  return $renderer->render($form);
54 }
$renderer
global $DIC
Definition: shib_login.php:26

◆ with_required()

ILIAS\UI\examples\Input\Field\with_required ( )


description: > Example showing the use of the withRequired() method

expected output: >

ILIAS shows the rendered Component.

Definition at line 32 of file with_required.php.

References $DIC, and $renderer.

33 {
34  //Step 0: Declare dependencies
35  global $DIC;
36  $ui = $DIC->ui()->factory();
37  $renderer = $DIC->ui()->renderer();
38  $request = $DIC->http()->request();
39 
40  // Step 1: define the text field and make it a required field,
41  // i.e. checking for its default requirement constraint
42  // (for text fields: value must have a minimum length of 1)
43  $text_input = $ui->input()->field()->text("Enter a name", "And make it a good one!");
44  $text_input = $text_input->withRequired(true);
45 
46  //Step 2: define form and form actions
47  $form = $ui->input()->container()->form()->standard('#', [ $text_input]);
48 
49  //Step 3: implement some form data processing.
50  if ($request->getMethod() == "POST") {
51  $form = $form->withRequest($request);
52  $result = $form->getData();
53  } else {
54  $result = "No result yet.";
55  }
56 
57  //Step 4: Render the checkbox with the enclosing form.
58  return
59  "<pre>" . print_r($result, true) . "</pre><br/>" .
60  $renderer->render($form);
61 }
$renderer
global $DIC
Definition: shib_login.php:26

◆ with_required_custom_constraint()

ILIAS\UI\examples\Input\Field\with_required_custom_constraint ( )


description: > Example showing the use of the withRequired() method with a custom constraint that replaces the default requirement constraint.

A custom constraint SHOULD be explained in the byline of the input.

expected output: >

ILIAS shows the rendered Component.

Definition at line 36 of file with_required_custom_constraint.php.

References $DIC, ILIAS\UI\examples\Layout\Page\Standard\$refinery, and $renderer.

37 {
38  //Step 0: Declare dependencies
39  global $DIC;
40  $ui = $DIC->ui()->factory();
41  $refinery = $DIC->refinery();
42  $renderer = $DIC->ui()->renderer();
43  $request = $DIC->http()->request();
44 
45  // Step 1: define the text field, make it a required field
46  // and add a custom constraint
47  $text_input = $ui->input()->field()->text("Enter a name", "Needs to start with an H");
48  $custom_constraint = $refinery->custom()->constraint(function ($value) {
49  return (substr($value, 0, 1) === 'H') ? true : false;
50  }, "Name does not start with an H");
51  $text_input = $text_input->withRequired(true, $custom_constraint);
52 
53  //Step 2: define form and form actions
54  $form = $ui->input()->container()->form()->standard('#', [ $text_input]);
55 
56  //Step 3: implement some form data processing.
57  if ($request->getMethod() == "POST") {
58  $form = $form->withRequest($request);
59  $result = $form->getData();
60  } else {
61  $result = "No result yet.";
62  }
63 
64  //Step 4: Render the checkbox with the enclosing form.
65  return
66  "<pre>" . print_r($result, true) . "</pre><br/>" .
67  $renderer->render($form);
68 }
$renderer
global $DIC
Definition: shib_login.php:26