ILIAS  release_8 Revision v8.24
MultiSelect.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\Data\Factory as DataFactory;
26use Closure;
27
32{
36 protected array $options = [];
37 private bool $complex = true;
38
42 public function __construct(
43 DataFactory $data_factory,
44 \ILIAS\Refinery\Factory $refinery,
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
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}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Factory for Date Formats.
Definition: Factory.php:27
Builds data types.
Definition: Factory.php:21
This implements the multi-select input.
Definition: MultiSelect.php:32
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: MultiSelect.php:98
__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:32
This describes inputs that can be used in forms.
Definition: FormInput.php:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Refinery Factory $refinery
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
Class ChatMainBarProvider \MainMenu\Provider.