ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables 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  private bool $complex = true;
38 
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  if (is_null($value)) {
67  return true;
68  }
69  if (is_array($value)) {
70  foreach ($value as $v) {
71  if (!array_key_exists($v, $this->options)) {
72  return false;
73  }
74  }
75  return true;
76  }
77  return false;
78  }
79 
83  protected function getConstraintForRequirement(): ?Constraint
84  {
85  if ($this->requirement_constraint !== null) {
86  return $this->requirement_constraint;
87  }
88 
89  return $this->refinery->custom()->constraint(
90  fn ($value) => is_array($value) && count($value) > 0,
91  "Empty"
92  );
93  }
94 
98  public function getUpdateOnLoadCode(): Closure
99  {
100  return fn ($id) => "var checkedBoxes = function() {
101  var options = [];
102  $('#$id').find('li').each(function() {
103  if ($(this).find('input').prop('checked')) {
104  options.push($(this).find('span').text());
105  }
106  });
107  return options.join(', ');
108  }
109  $('#$id').on('input', function(event) {
110  il.UI.input.onFieldUpdate(event, '$id', checkedBoxes());
111  });
112  il.UI.input.onFieldUpdate(event, '$id', checkedBoxes());
113  ";
114  }
115 
119  public function isComplex(): bool
120  {
121  return $this->complex;
122  }
123 }
Class ChatMainBarProvider .
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, array $options, ?string $byline)
Definition: MultiSelect.php:42
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
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: MultiSelect.php:98
This implements the multi-select input.
Definition: MultiSelect.php:31
__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