ILIAS  trunk Revision v11.0_alpha-1731-gff9cd7e2bd3
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
MultiSelect.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
23 use ILIAS\UI\Component as C;
26 use Closure;
27 
31 class MultiSelect extends FormInput implements C\Input\Field\MultiSelect
32 {
36  protected array $options = [];
37 
41  public function __construct(
42  DataFactory $data_factory,
44  string $label,
45  array $options,
46  ?string $byline
47  ) {
48  parent::__construct($data_factory, $refinery, $label, $byline);
49  $this->options = $options;
50  }
51 
55  public function getOptions(): array
56  {
57  return $this->options;
58  }
59 
63  protected function isClientSideValueOk($value): bool
64  {
65  if (is_null($value)) {
66  return true;
67  }
68  if (is_array($value)) {
69  foreach ($value as $v) {
70  if (!array_key_exists($v, $this->options)) {
71  return false;
72  }
73  }
74  return true;
75  }
76  return false;
77  }
78 
82  protected function getConstraintForRequirement(): ?Constraint
83  {
84  if ($this->requirement_constraint !== null) {
86  }
87 
88  return $this->refinery->custom()->constraint(
89  fn($value) => is_array($value) && count($value) > 0,
90  "Empty"
91  );
92  }
93 
97  public function getUpdateOnLoadCode(): Closure
98  {
99  return fn($id) => "var checkedBoxes = function() {
100  var options = [];
101  $('#$id').find('li').each(function() {
102  if ($(this).find('input').prop('checked')) {
103  options.push($(this).find('span').text());
104  }
105  });
106  return options.join(', ');
107  }
108  $('#$id').on('input', function(event) {
109  il.UI.input.onFieldUpdate(event, '$id', checkedBoxes());
110  });
111  il.UI.input.onFieldUpdate(event, '$id', checkedBoxes());
112  ";
113  }
114 
118  public function isComplex(): bool
119  {
120  return true;
121  }
122 }
Interface Observer Contains several chained tasks and infos about them.
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, array $options, ?string $byline)
Definition: MultiSelect.php:41
A constraint encodes some resrtictions on values.
Definition: Constraint.php:31
Factory for Date Formats.
Definition: Factory.php:26
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This implements the multi-select input.
Definition: MultiSelect.php:31
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
__construct(Container $dic, ilPlugin $plugin)
This describes inputs that can be used in forms.
Definition: FormInput.php:32