ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
Checkbox.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
28use Closure;
29use LogicException;
30use InvalidArgumentException;
31
36{
38
43 {
44 if ($this->requirement_constraint !== null) {
45 return $this->requirement_constraint;
46 }
47
48 return null;
49 }
50
54 protected function isClientSideValueOk($value): bool
55 {
56 return $value === "checked" || $value === "" || is_bool($value);
57 }
58
59
63 public function withValue($value): self
64 {
65 return parent::withValue($value ?? false);
66 }
67
68
72 public function withInput(InputData $input): self
73 {
74 if ($this->getName() === null) {
75 throw new LogicException("Can only collect if input has a name.");
76 }
77
78 if (!$this->isDisabled()) {
79 $value = $input->getOr($this->getName(), "");
80 $clone = $this->withValue($value === "checked");
81 } else {
82 $clone = $this;
83 }
84
85 $clone->content = $this->applyOperationsTo($clone->getValue());
86 if ($clone->content->isError()) {
88 return $clone->withError("" . $clone->content->error());
89 }
90
91 return $clone;
92 }
93
97 public function appendOnLoad(C\Signal $signal): C\Onloadable
98 {
99 return $this->appendTriggeredSignal($signal, 'load');
100 }
101
105 public function withOnChange(C\Signal $signal): C\Changeable
106 {
107 return $this->withTriggeredSignal($signal, 'change');
108 }
109
113 public function appendOnChange(C\Signal $signal): C\Changeable
114 {
115 return $this->appendTriggeredSignal($signal, 'change');
116 }
117
121 public function withOnLoad(C\Signal $signal): C\Onloadable
122 {
123 return $this->withTriggeredSignal($signal, 'load');
124 }
125
129 public function getUpdateOnLoadCode(): Closure
130 {
131 return fn($id) => "$('#$id').on('input', function(event) {
132 il.UI.input.onFieldUpdate(event, '$id', $('#$id').prop('checked').toString());
133 });
134 il.UI.input.onFieldUpdate(event, '$id', $('#$id').prop('checked').toString());";
135 }
136}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This implements the checkbox input.
Definition: Checkbox.php:36
getUpdateOnLoadCode()
Get update code.This method has to return JS code that calls il.UI.filter.onFieldUpdate(event,...
Definition: Checkbox.php:129
withValue($value)
Get an input like this with another value displayed on the client side.static
Definition: Checkbox.php:63
A constraint encodes some resrtictions on values.
Definition: Constraint.php:32
This describes inputs that can be used in forms.
Definition: FormInput.php:33
Describes how Input-Elements want to interact with posted data.
Definition: InputData.php:30
getOr(string $name, $default)
Get a named value from the data and fallback to default if that name does not exist.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: Checkbox.php:21
withValue($value)
Get an input like this with another value displayed on the client side.
Definition: Group.php:61
appendTriggeredSignal(C\Signal $signal, string $event)
Append a triggered signal to other signals of the same event.
Definition: Triggerer.php:47
withTriggeredSignal(C\Signal $signal, string $event)
Add a triggered signal, replacing any other signals registered on the same event.
Definition: Triggerer.php:62
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.