ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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
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
83 {
84 if ($this->requirement_constraint !== null) {
85 return $this->requirement_constraint;
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) => "(function() {
100 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 true;
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:36
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:97
__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:32
This describes inputs that can be used in forms.
Definition: FormInput.php:33
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.