ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Select.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use ILIAS\Data\Factory as DataFactory;
26use Closure;
27
31class Select extends FormInput implements C\Input\Field\Select
32{
33 protected array $options;
34 protected string $label;
35
39 protected $value;
40
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 return in_array($value, array_keys($this->options)) || $value == "";
66 }
67
72 {
73 if ($this->requirement_constraint !== null) {
74 return $this->requirement_constraint;
75 }
76
77 return $this->refinery->logical()->sequential([
78 $this->refinery->to()->string(),
79 $this->refinery->string()->hasMinLength(1)
80 ])->withProblemBuilder(function ($txt) {
81 return $txt('required');
82 });
83 }
84
88 public function getUpdateOnLoadCode(): Closure
89 {
90 return fn($id) => "$('#$id').on('input', function(event) {
91 il.UI.input.onFieldUpdate(event, '$id', $('#$id option:selected').text());
92 });
93 il.UI.input.onFieldUpdate(event, '$id', $('#$id option:selected').text());";
94 }
95
99 public function isComplex(): bool
100 {
101 return false;
102 }
103}
$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
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, string $label, array $options, ?string $byline)
Definition: Select.php:41
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: Select.php:88
$txt
Definition: error.php:31
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.