19declare(strict_types=1);
45 string $a_postvar =
""
49 $this->
lng = $DIC->language();
55 $this->suffix = $a_value;
63 public function setValue(?
string $a_value): void
65 if ($a_value ==
"" || is_null($a_value)) {
69 $this->value = (float) str_replace(
',',
'.', $a_value);
73 $this->value = round($this->value);
78 $this->value = round($this->value, $this->
getDecimals());
81 $this->value = (float) number_format($this->value, $this->
getDecimals(),
".",
"");
92 $data = unserialize($a_data);
104 $this->maxlength = $a_maxlength;
136 $this->size = $a_size;
151 bool $a_display_always =
false
153 $this->minvalue = $a_minvalue;
154 $this->minvalue_visible = $a_display_always;
159 return $this->minvalue;
164 bool $a_display_always =
false
166 $this->maxvalue = $a_maxvalue;
167 $this->maxvalue_visible = $a_display_always;
172 return $this->maxvalue;
177 $this->decimals = $a_decimals;
178 if ($this->decimals) {
179 $this->allowDecimals(
true);
185 return $this->decimals;
190 $this->allow_decimals = $a_value;
195 return $this->allow_decimals;
202 $val = trim($this->
str($this->getPostVar()));
203 if ($this->getRequired() && $val ==
"") {
204 $this->setAlert(
$lng->txt(
"msg_input_is_required"));
207 $val = str_replace(
',',
'.', $val);
209 if ($val !=
"" && !is_numeric($val)) {
210 $this->minvalue_visible =
true;
211 $this->maxvalue_visible =
true;
212 $this->setAlert(
$lng->txt(
"form_msg_numeric_value_required"));
216 if ($this->minvalueShouldBeGreater()) {
217 if ($val !=
"" && $this->getMinValue() !==
null &&
218 $val <= $this->getMinValue()) {
219 $this->minvalue_visible =
true;
220 $this->setAlert(
$lng->txt(
"form_msg_value_too_low"));
225 $this->getMinValue() !==
null &&
226 $val < $this->getMinValue()) {
227 $this->minvalue_visible =
true;
228 $this->setAlert(
$lng->txt(
"form_msg_value_too_low"));
233 if ($this->maxvalueShouldBeLess()) {
235 $this->getMaxValue() !==
null &&
236 $val >= $this->getMaxValue()) {
237 $this->maxvalue_visible =
true;
238 $this->setAlert(
$lng->txt(
"form_msg_value_too_high"));
243 $this->getMaxValue() !==
null &&
244 $val > $this->getMaxValue()) {
245 $this->maxvalue_visible =
true;
246 $this->setAlert(
$lng->txt(
"form_msg_value_too_high"));
251 return $this->checkSubItemsInput();
256 $value = $this->
str($this->getPostVar());
257 if (trim($value) ==
"") {
260 return (
float) str_replace(
',',
'.', $value);
265 $html = $this->render();
276 $tpl =
new ilTemplate(
"tpl.prop_number.html",
true,
true,
"components/ILIAS/Form");
278 if (strlen((
string) $this->
getValue())) {
279 $tpl->setCurrentBlock(
"prop_number_propval");
281 $tpl->parseCurrentBlock();
284 if ($this->getInfo() !==
'') {
285 $tpl->setCurrentBlock(
'described_by_description');
286 $tpl->setVariable(
'DESCRIBED_BY_DESCRIPTION_FIELD_ID', $this->getFieldId());
287 $tpl->parseCurrentBlock();
293 if ($this->areDecimalsAllowed() && $this->getDecimals() > 0) {
294 $constraints =
$lng->txt(
"form_format") .
": ###." . str_repeat(
"#", $this->getDecimals());
297 if ($this->getMinValue() !==
null && $this->minvalue_visible) {
298 $constraints .= $delim .
$lng->txt(
"form_min_value") .
": " . (($this->minvalueShouldBeGreater()) ?
"> " :
"") . $this->getMinValue();
301 if ($this->getMaxValue() !==
null && $this->maxvalue_visible) {
302 $constraints .= $delim .
$lng->txt(
"form_max_value") .
": " . (($this->maxvalueShouldBeLess()) ?
"< " :
"") . $this->getMaxValue();
306 if ($constraints !==
"") {
307 $tpl->setCurrentBlock(
'described_by_constraint');
308 $tpl->setVariable(
'DESCRIBED_BY_CONSTRAINT_FIELD_ID', $this->getFieldId());
309 $tpl->parseCurrentBlock();
312 $tpl->setCurrentBlock(
"prop_number");
314 $tpl->setVariable(
"POST_VAR", $this->getPostVar());
315 $tpl->setVariable(
"ID", $this->getFieldId());
316 $tpl->setVariable(
"SIZE", $this->getSize());
317 $tpl->setVariable(
"MAXLENGTH", $this->getMaxLength());
318 if (strlen($this->getSuffix())) {
319 $tpl->setVariable(
"INPUT_SUFFIX", $this->getSuffix());
321 if ($this->getDisabled()) {
324 " disabled=\"disabled\""
328 if ($this->client_side_validation) {
329 $tpl->setVariable(
"JS_DECIMALS_ALLOWED", (
int) $this->areDecimalsAllowed());
330 $tpl->setVariable(
"JS_ID", $this->getFieldId());
333 if ($constraints !==
'') {
334 $tpl->setVariable(
"TXT_NUMBER_CONSTRAINTS", $constraints);
341 if ($this->getRequired()) {
342 $tpl->setVariable(
"REQUIRED",
"required=\"required\"");
345 $tpl->parseCurrentBlock();
352 return $this->getInput();
357 $this->client_side_validation = $validate;
setVariable($variable, $value='')
Sets a variable value.
special template class to simplify handling of ITX/PEAR
setCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
parseCurrentBlock(string $part=ilGlobalTemplateInterface::DEFAULT_BLOCK)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc