ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
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{
34
38 public function __construct(
39 DataFactory $data_factory,
41 string $label,
42 array $options,
43 ?string $byline
44 ) {
45 parent::__construct($data_factory, $refinery, $label, $byline);
46 $this->options = $options;
47 }
48
52 protected function isClientSideValueOk($value): bool
53 {
54 if (is_null($value)) {
55 return true;
56 }
57 if (is_array($value)) {
58 foreach ($value as $v) {
59 if (!array_key_exists($v, $this->options)) {
60 return false;
61 }
62 }
63 return true;
64 }
65 return false;
66 }
67
72 {
73 if ($this->requirement_constraint !== null) {
74 return $this->requirement_constraint;
75 }
76
77 return $this->refinery->custom()->constraint(
78 fn($value) => is_array($value) && count($value) > 0,
79 "Empty"
80 );
81 }
82
86 public function getUpdateOnLoadCode(): Closure
87 {
88 return fn($id) => "(function() {
89 var checkedBoxes = function() {
90 var options = [];
91 $('#$id').find('li').each(function() {
92 if ($(this).find('input').prop('checked')) {
93 options.push($(this).find('span').text());
94 }
95 });
96 return options.join(', ');
97 }
98 $('#$id').on('input', function(event) {
99 il.UI.input.onFieldUpdate(event, '$id', checkedBoxes());
100 });
101 il.UI.input.onFieldUpdate(event, '$id', checkedBoxes());
102 })();";
103 }
104
108 public function isComplex(): bool
109 {
110 return true;
111 }
112}
$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:86
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, array $options, ?string $byline)
Definition: MultiSelect.php:38
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.