ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
Select.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 use ILIAS\UI\Component as C;
26 use Closure;
27 
31 class Select extends FormInput implements C\Input\Field\Select
32 {
33  protected array $options;
34  protected string $label;
35 
39  protected $value;
40  private bool $complex = false;
41 
42  public function __construct(
43  DataFactory $data_factory,
45  string $label,
46  array $options,
47  ?string $byline
48  ) {
49  parent::__construct($data_factory, $refinery, $label, $byline);
50  $this->options = $options;
51  }
52 
56  public function getOptions(): array
57  {
58  return $this->options;
59  }
60 
64  protected function isClientSideValueOk($value): bool
65  {
66  return in_array($value, array_keys($this->options)) || $value == "";
67  }
68 
72  protected function getConstraintForRequirement(): ?Constraint
73  {
74  if ($this->requirement_constraint !== null) {
75  return $this->requirement_constraint;
76  }
77 
78  return $this->refinery->logical()->sequential([
79  $this->refinery->to()->string(),
80  $this->refinery->string()->hasMinLength(1)
81  ]);
82  }
83 
87  public function getUpdateOnLoadCode(): Closure
88  {
89  return fn ($id) => "$('#$id').on('input', function(event) {
90  il.UI.input.onFieldUpdate(event, '$id', $('#$id option:selected').text());
91  });
92  il.UI.input.onFieldUpdate(event, '$id', $('#$id option:selected').text());";
93  }
94 
98  public function isComplex(): bool
99  {
100  return $this->complex;
101  }
102 }
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
A constraint encodes some resrtictions on values.
Definition: Constraint.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, array $options, ?string $byline)
Definition: Select.php:42
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event, &#39;$id&#39;, string_value);initially "onload" andon every input change. It must pass a readable string representation of its value in parameter &#39;string_value&#39;.
Definition: Select.php:87
__construct(Container $dic, ilPlugin $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This describes inputs that can be used in forms.
Definition: FormInput.php:31
Refinery Factory $refinery