ILIAS  release_7 Revision v7.30-3-g800a261c036
Textarea.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 2017 Jesús lópez <lopez@leifos.com> Extended GPL, see docs/LICENSE */
4
6
10use ILIAS\Data\Factory as DataFactory;
11
15class Textarea extends Input implements C\Input\Field\Textarea
16{
18
19 protected $max_limit;
20 protected $min_limit;
21
25 public function __construct(
26 DataFactory $data_factory,
27 \ILIAS\Refinery\Factory $refinery,
28 $label,
29 $byline
30 ) {
31 parent::__construct($data_factory, $refinery, $label, $byline);
32 $this->setAdditionalTransformation(
33 $refinery->string()->stripTags()
34 );
35 }
36
42 public function withMaxLimit($max_limit)
43 {
47 $clone = $this->withAdditionalTransformation(
48 $this->refinery->string()->hasMaxLength($max_limit)
49 );
50 $clone->max_limit = $max_limit;
51 return $clone;
52 }
53
58 public function getMaxLimit()
59 {
60 return $this->max_limit;
61 }
62
68 public function withMinLimit($min_limit)
69 {
73 $clone = $this->withAdditionalTransformation(
74 $this->refinery->string()->hasMinLength($min_limit)
75 );
76 $clone->min_limit = $min_limit;
77 return $clone;
78 }
79
84 public function getMinLimit()
85 {
86 return $this->min_limit;
87 }
88
92 protected function isClientSideValueOk($value) : bool
93 {
94 return is_string($value);
95 }
96
97
101 protected function getConstraintForRequirement()
102 {
103 if ($this->min_limit) {
104 return $this->refinery->string()->hasMinLength($this->min_limit);
105 }
106 return $this->refinery->string()->hasMinLength(1);
107 }
108
112 public function isLimited()
113 {
114 if ($this->min_limit || $this->max_limit) {
115 return true;
116 }
117 return false;
118 }
119
123 public function getUpdateOnLoadCode() : \Closure
124 {
125 return function ($id) {
126 $code = "$('#$id').on('input', function(event) {
127 il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());
128 });
129 il.UI.input.onFieldUpdate(event, '$id', $('#$id').val());";
130 return $code;
131 };
132 }
133}
An exception for terminatinating execution or to throw for unit testing.
Builds data types.
Definition: Factory.php:20
getMaxLimit()
get maximum limit of characters
Definition: Textarea.php:58
getMinLimit()
get minimum limit of characters
Definition: Textarea.php:84
__construct(DataFactory $data_factory, \ILIAS\Refinery\Factory $refinery, $label, $byline)
Definition: Textarea.php:25
This describes commonalities between all inputs.
Definition: Input.php:32
withAdditionalTransformation(Transformation $trafo)
Apply a transformation to the content of the input.
This describes Textarea inputs.
Definition: Textarea.php:13
withMinLimit($min_limit)
set minimum number of characters
Definition: Textarea.php:68
withMaxLimit($max_limit)
set maximum number of characters
Definition: Textarea.php:42
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
trait JavaScriptBindable
Trait for components implementing JavaScriptBindable providing standard implementation.
Class ChatMainBarProvider \MainMenu\Provider.