|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* TTextBox class file. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Qiang Xue <[email protected]> |
|
6
|
|
|
* @link https://github.com/pradosoft/prado |
|
7
|
|
|
* @copyright Copyright © 2005-2016 The PRADO Group |
|
8
|
|
|
* @license https://github.com/pradosoft/prado/blob/master/LICENSE |
|
9
|
|
|
* @package Prado\Web\UI\WebControls |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Prado\Web\UI\WebControls; |
|
13
|
|
|
|
|
14
|
|
|
use Prado\Prado; |
|
15
|
|
|
use Prado\TPropertyValue; |
|
16
|
|
|
use Prado\Web\THttpUtility; |
|
17
|
|
|
use Prado\Exceptions\TInvalidDataValueException; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* TTextBox class |
|
21
|
|
|
* |
|
22
|
|
|
* TTextBox displays a text box on the Web page for user input. |
|
23
|
|
|
* The text displayed in the TTextBox control is determined by the |
|
24
|
|
|
* {@link setText Text} property. You can create a <b>SingleLine</b>, |
|
25
|
|
|
* a <b>MultiLine</b>, or a <b>Password</b> text box by setting |
|
26
|
|
|
* the {@link setTextMode TextMode} property. If the TTextBox control |
|
27
|
|
|
* is a multiline text box, the number of rows it displays is determined |
|
28
|
|
|
* by the {@link setRows Rows} property, and the {@link setWrap Wrap} property |
|
29
|
|
|
* can be used to determine whether to wrap the text in the component. |
|
30
|
|
|
* Additional {@link setTextMode TextMode} types enable the use of new input types |
|
31
|
|
|
* added with html5, eg. <b>Color</b>, <b>Date</b>, <b>Email</b>. |
|
32
|
|
|
* |
|
33
|
|
|
* To specify the display width of the text box, in characters, set |
|
34
|
|
|
* the {@link setColumns Columns} property. To prevent the text displayed |
|
35
|
|
|
* in the component from being modified, set the {@link setReadOnly ReadOnly} |
|
36
|
|
|
* property to true. If you want to limit the user input to a specified number |
|
37
|
|
|
* of characters, set the {@link setMaxLength MaxLength} property. |
|
38
|
|
|
* To use AutoComplete feature, set the {@link setAutoCompleteType AutoCompleteType} property. |
|
39
|
|
|
* |
|
40
|
|
|
* If {@link setAutoPostBack AutoPostBack} is set true, updating the text box |
|
41
|
|
|
* and then changing the focus out of it will cause postback action. |
|
42
|
|
|
* And if {@link setCausesValidation CausesValidation} is true, validation will |
|
43
|
|
|
* also be processed, which can be further restricted within |
|
44
|
|
|
* a {@link setValidationGroup ValidationGroup}. |
|
45
|
|
|
* |
|
46
|
|
|
* WARNING: Be careful if you want to display the text collected via TTextBox. |
|
47
|
|
|
* Malicious cross-site script may be injected in. You may use {@link getSafeText SafeText} |
|
48
|
|
|
* to prevent this problem. |
|
49
|
|
|
* |
|
50
|
|
|
* NOTE: If you set {@link setWrap Wrap} to false or use {@link setAutoCompleteType AutoCompleteType}, |
|
51
|
|
|
* the generated HTML output for the textbox will not be XHTML-compatible. |
|
52
|
|
|
* Currently, no alternatives are available. |
|
53
|
|
|
* |
|
54
|
|
|
* @author Qiang Xue <[email protected]> |
|
55
|
|
|
* @package Prado\Web\UI\WebControls |
|
56
|
|
|
* @since 3.0 |
|
57
|
|
|
*/ |
|
58
|
|
|
class TTextBox extends \Prado\Web\UI\WebControls\TWebControl implements \Prado\Web\UI\IPostBackDataHandler, \Prado\Web\UI\IValidatable, \Prado\IDataRenderer |
|
59
|
|
|
{ |
|
60
|
|
|
/** |
|
61
|
|
|
* Default number of rows (for MultiLine text box) |
|
62
|
|
|
*/ |
|
63
|
|
|
const DEFAULT_ROWS = 4; |
|
64
|
|
|
/** |
|
65
|
|
|
* Default number of columns (for MultiLine text box) |
|
66
|
|
|
*/ |
|
67
|
|
|
const DEFAULT_COLUMNS = 20; |
|
68
|
|
|
/** |
|
69
|
|
|
* @var mixed safe text parser |
|
70
|
|
|
*/ |
|
71
|
|
|
private static $_safeTextParser = null; |
|
72
|
|
|
/** |
|
73
|
|
|
* @var string safe textbox content with javascript stripped off |
|
74
|
|
|
*/ |
|
75
|
|
|
private $_safeText; |
|
76
|
|
|
private $_dataChanged = false; |
|
77
|
|
|
private $_isValid = true; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @return string tag name of the textbox |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function getTagName() |
|
83
|
|
|
{ |
|
84
|
|
|
return ($this->getTextMode() === 'MultiLine') ? 'textarea' : 'input'; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @return bool whether to render javascript. |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getEnableClientScript() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->getViewState('EnableClientScript', true); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @param bool $value whether to render javascript. |
|
97
|
|
|
*/ |
|
98
|
|
|
public function setEnableClientScript($value) |
|
99
|
|
|
{ |
|
100
|
|
|
$this->setViewState('EnableClientScript', TPropertyValue::ensureBoolean($value), true); |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Adds attribute name-value pairs to renderer. |
|
105
|
|
|
* This method overrides the parent implementation with additional textbox specific attributes. |
|
106
|
|
|
* @param THtmlWriter $writer the writer used for the rendering purpose |
|
107
|
|
|
*/ |
|
108
|
|
|
protected function addAttributesToRender($writer) |
|
109
|
|
|
{ |
|
110
|
|
|
$page = $this->getPage(); |
|
111
|
|
|
$page->ensureRenderInForm($this); |
|
112
|
|
|
if (($uid = $this->getUniqueID()) !== '') { |
|
113
|
|
|
$writer->addAttribute('name', $uid); |
|
114
|
|
|
} |
|
115
|
|
|
if (($textMode = $this->getTextMode()) === TTextBoxMode::MultiLine) { |
|
116
|
|
|
if (($rows = $this->getRows()) <= 0) { |
|
117
|
|
|
$rows = self::DEFAULT_ROWS; |
|
118
|
|
|
} |
|
119
|
|
|
if (($cols = $this->getColumns()) <= 0) { |
|
120
|
|
|
$cols = self::DEFAULT_COLUMNS; |
|
121
|
|
|
} |
|
122
|
|
|
$writer->addAttribute('rows', "$rows"); |
|
123
|
|
|
$writer->addAttribute('cols', "$cols"); |
|
124
|
|
|
if (!$this->getWrap()) { |
|
125
|
|
|
$writer->addAttribute('wrap', 'off'); |
|
126
|
|
|
} |
|
127
|
|
|
} else { |
|
128
|
|
|
switch ($textMode) { |
|
129
|
|
|
case TTextBoxMode::Password: |
|
130
|
|
|
$writer->addAttribute('type', 'password'); |
|
131
|
|
|
break; |
|
132
|
|
|
case TTextBoxMode::Color: |
|
133
|
|
|
$writer->addAttribute('type', 'color'); |
|
134
|
|
|
break; |
|
135
|
|
|
case TTextBoxMode::Date: |
|
136
|
|
|
$writer->addAttribute('type', 'date'); |
|
137
|
|
|
break; |
|
138
|
|
|
case TTextBoxMode::Datetime: |
|
139
|
|
|
$writer->addAttribute('type', 'datetime'); |
|
140
|
|
|
break; |
|
141
|
|
|
case TTextBoxMode::DatetimeLocal: |
|
142
|
|
|
$writer->addAttribute('type', 'datetime-local'); |
|
143
|
|
|
break; |
|
144
|
|
|
case TTextBoxMode::Email: |
|
145
|
|
|
$writer->addAttribute('type', 'email'); |
|
146
|
|
|
break; |
|
147
|
|
|
case TTextBoxMode::Month: |
|
148
|
|
|
$writer->addAttribute('type', 'month'); |
|
149
|
|
|
break; |
|
150
|
|
|
case TTextBoxMode::Number: |
|
151
|
|
|
$writer->addAttribute('type', 'number'); |
|
152
|
|
|
break; |
|
153
|
|
|
case TTextBoxMode::Range: |
|
154
|
|
|
$writer->addAttribute('type', 'range'); |
|
155
|
|
|
break; |
|
156
|
|
|
case TTextBoxMode::Search: |
|
157
|
|
|
$writer->addAttribute('type', 'search'); |
|
158
|
|
|
break; |
|
159
|
|
|
case TTextBoxMode::Tel: |
|
160
|
|
|
$writer->addAttribute('type', 'tel'); |
|
161
|
|
|
break; |
|
162
|
|
|
case TTextBoxMode::Time: |
|
163
|
|
|
$writer->addAttribute('type', 'time'); |
|
164
|
|
|
break; |
|
165
|
|
|
case TTextBoxMode::Url: |
|
166
|
|
|
$writer->addAttribute('type', 'url'); |
|
167
|
|
|
break; |
|
168
|
|
|
case TTextBoxMode::Week: |
|
169
|
|
|
$writer->addAttribute('type', 'week'); |
|
170
|
|
|
break; |
|
171
|
|
|
case TTextBoxMode::SingleLine: |
|
172
|
|
|
default: |
|
173
|
|
|
$writer->addAttribute('type', 'text'); |
|
174
|
|
|
break; |
|
175
|
|
|
} |
|
176
|
|
|
|
|
177
|
|
|
if (($text = $this->getText()) !== '' && ($textMode !== TTextBoxMode::Password || $this->getPersistPassword())) { |
|
178
|
|
|
$writer->addAttribute('value', $text); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
if (($act = $this->getAutoCompleteType()) !== 'None') { |
|
182
|
|
|
if ($act === 'Disabled') { |
|
183
|
|
|
$writer->addAttribute('autocomplete', 'off'); |
|
184
|
|
|
} elseif ($act === 'Search') { |
|
185
|
|
|
$writer->addAttribute('vcard_name', 'search'); |
|
186
|
|
|
} elseif ($act === 'HomeCountryRegion') { |
|
187
|
|
|
$writer->addAttribute('vcard_name', 'HomeCountry'); |
|
188
|
|
|
} elseif ($act === 'BusinessCountryRegion') { |
|
189
|
|
|
$writer->addAttribute('vcard_name', 'BusinessCountry'); |
|
190
|
|
|
} else { |
|
191
|
|
|
if (strpos($act, 'Business') === 0) { |
|
192
|
|
|
$act = 'Business' . '.' . substr($act, 8); |
|
193
|
|
|
} elseif (strpos($act, 'Home') === 0) { |
|
194
|
|
|
$act = 'Home' . '.' . substr($act, 4); |
|
195
|
|
|
} |
|
196
|
|
|
$writer->addAttribute('vcard_name', 'vCard.' . $act); |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|
|
200
|
|
|
if (($cols = $this->getColumns()) > 0) { |
|
201
|
|
|
$writer->addAttribute('size', "$cols"); |
|
202
|
|
|
} |
|
203
|
|
|
if (($maxLength = $this->getMaxLength()) > 0) { |
|
204
|
|
|
$writer->addAttribute('maxlength', "$maxLength"); |
|
205
|
|
|
} |
|
206
|
|
|
} |
|
207
|
|
|
if ($this->getReadOnly()) { |
|
208
|
|
|
$writer->addAttribute('readonly', 'readonly'); |
|
209
|
|
|
} |
|
210
|
|
|
$isEnabled = $this->getEnabled(true); |
|
211
|
|
|
if (!$isEnabled && $this->getEnabled()) { // in this case parent will not render 'disabled' |
|
212
|
|
|
$writer->addAttribute('disabled', 'disabled'); |
|
213
|
|
|
} |
|
214
|
|
|
if ($isEnabled |
|
215
|
|
|
&& $this->getEnableClientScript() |
|
216
|
|
|
&& ($this->getAutoPostBack() || $textMode === TTextBoxMode::SingleLine) |
|
217
|
|
|
&& $page->getClientSupportsJavaScript()) { |
|
218
|
|
|
$this->renderClientControlScript($writer); |
|
219
|
|
|
} |
|
220
|
|
|
parent::addAttributesToRender($writer); |
|
221
|
|
|
} |
|
222
|
|
|
|
|
223
|
|
|
/** |
|
224
|
|
|
* Renders the javascript for textbox. |
|
225
|
|
|
* @param mixed $writer |
|
226
|
|
|
*/ |
|
227
|
|
|
protected function renderClientControlScript($writer) |
|
228
|
|
|
{ |
|
229
|
|
|
$writer->addAttribute('id', $this->getClientID()); |
|
230
|
|
|
$cs = $this->getPage()->getClientScript(); |
|
231
|
|
|
$cs->registerPostBackControl($this->getClientClassName(), $this->getPostBackOptions()); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Gets the name of the javascript class responsible for performing postback for this control. |
|
236
|
|
|
* This method overrides the parent implementation. |
|
237
|
|
|
* @return string the javascript class name |
|
238
|
|
|
*/ |
|
239
|
|
|
protected function getClientClassName() |
|
240
|
|
|
{ |
|
241
|
|
|
return 'Prado.WebUI.TTextBox'; |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Gets the post back options for this textbox. |
|
246
|
|
|
* @return array |
|
247
|
|
|
*/ |
|
248
|
|
View Code Duplication |
protected function getPostBackOptions() |
|
|
|
|
|
|
249
|
|
|
{ |
|
250
|
|
|
$options['ID'] = $this->getClientID(); |
|
|
|
|
|
|
251
|
|
|
$options['EventTarget'] = $this->getUniqueID(); |
|
252
|
|
|
$options['AutoPostBack'] = $this->getAutoPostBack(); |
|
253
|
|
|
$options['CausesValidation'] = $this->getCausesValidation(); |
|
254
|
|
|
$options['ValidationGroup'] = $this->getValidationGroup(); |
|
255
|
|
|
$options['TextMode'] = $this->getTextMode(); |
|
256
|
|
|
return $options; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Loads user input data. |
|
261
|
|
|
* This method is primarly used by framework developers. |
|
262
|
|
|
* @param string $key the key that can be used to retrieve data from the input data collection |
|
263
|
|
|
* @param array $values the input data collection |
|
264
|
|
|
* @return bool whether the data of the component has been changed |
|
265
|
|
|
*/ |
|
266
|
|
|
public function loadPostData($key, $values) |
|
267
|
|
|
{ |
|
268
|
|
|
$value = $values[$key]; |
|
269
|
|
|
if ($this->getAutoTrim()) { |
|
270
|
|
|
$value = trim($value); |
|
271
|
|
|
} |
|
272
|
|
View Code Duplication |
if (!$this->getReadOnly() && $this->getText() !== $value) { |
|
|
|
|
|
|
273
|
|
|
$this->setText($value); |
|
274
|
|
|
return $this->_dataChanged = true; |
|
275
|
|
|
} else { |
|
276
|
|
|
return false; |
|
277
|
|
|
} |
|
278
|
|
|
} |
|
279
|
|
|
|
|
280
|
|
|
/** |
|
281
|
|
|
* Returns a value indicating whether postback has caused the control data change. |
|
282
|
|
|
* This method is required by the \Prado\Web\UI\IPostBackDataHandler interface. |
|
283
|
|
|
* @return bool whether postback has caused the control data change. False if the page is not in postback mode. |
|
284
|
|
|
*/ |
|
285
|
|
|
public function getDataChanged() |
|
286
|
|
|
{ |
|
287
|
|
|
return $this->_dataChanged; |
|
288
|
|
|
} |
|
289
|
|
|
|
|
290
|
|
|
/** |
|
291
|
|
|
* Returns the value to be validated. |
|
292
|
|
|
* This methid is required by \Prado\Web\UI\IValidatable interface. |
|
293
|
|
|
* @return mixed the value of the property to be validated. |
|
294
|
|
|
*/ |
|
295
|
|
|
public function getValidationPropertyValue() |
|
296
|
|
|
{ |
|
297
|
|
|
return $this->getText(); |
|
298
|
|
|
} |
|
299
|
|
|
|
|
300
|
|
|
/** |
|
301
|
|
|
* Returns true if this control validated successfully. |
|
302
|
|
|
* Defaults to true. |
|
303
|
|
|
* @return bool wether this control validated successfully. |
|
304
|
|
|
*/ |
|
305
|
|
|
public function getIsValid() |
|
306
|
|
|
{ |
|
307
|
|
|
return $this->_isValid; |
|
308
|
|
|
} |
|
309
|
|
|
/** |
|
310
|
|
|
* @param bool $value wether this control is valid. |
|
311
|
|
|
*/ |
|
312
|
|
|
public function setIsValid($value) |
|
313
|
|
|
{ |
|
314
|
|
|
$this->_isValid = TPropertyValue::ensureBoolean($value); |
|
315
|
|
|
} |
|
316
|
|
|
|
|
317
|
|
|
/** |
|
318
|
|
|
* Raises <b>OnTextChanged</b> event. |
|
319
|
|
|
* This method is invoked when the value of the {@link getText Text} |
|
320
|
|
|
* property changes on postback. |
|
321
|
|
|
* If you override this method, be sure to call the parent implementation to ensure |
|
322
|
|
|
* the invocation of the attached event handlers. |
|
323
|
|
|
* @param TEventParameter $param event parameter to be passed to the event handlers |
|
324
|
|
|
*/ |
|
325
|
|
|
public function onTextChanged($param) |
|
326
|
|
|
{ |
|
327
|
|
|
$this->raiseEvent('OnTextChanged', $this, $param); |
|
328
|
|
|
} |
|
329
|
|
|
|
|
330
|
|
|
/** |
|
331
|
|
|
* Raises postdata changed event. |
|
332
|
|
|
* This method is required by {@link \Prado\Web\UI\IPostBackDataHandler} interface. |
|
333
|
|
|
* It is invoked by the framework when {@link getText Text} property |
|
334
|
|
|
* is changed on postback. |
|
335
|
|
|
* This method is primarly used by framework developers. |
|
336
|
|
|
*/ |
|
337
|
|
|
public function raisePostDataChangedEvent() |
|
338
|
|
|
{ |
|
339
|
|
|
if ($this->getAutoPostBack() && $this->getCausesValidation()) { |
|
340
|
|
|
$this->getPage()->validate($this->getValidationGroup()); |
|
341
|
|
|
} |
|
342
|
|
|
$this->onTextChanged(null); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
/** |
|
346
|
|
|
* Renders the body content of the textbox when it is in MultiLine text mode. |
|
347
|
|
|
* @param THtmlWriter $writer the writer for rendering |
|
348
|
|
|
*/ |
|
349
|
|
|
public function renderContents($writer) |
|
350
|
|
|
{ |
|
351
|
|
|
if ($this->getTextMode() === 'MultiLine') { |
|
352
|
|
|
$writer->write(THttpUtility::htmlEncode($this->getText())); |
|
353
|
|
|
} |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* Renders an additional line-break after the opening tag when it |
|
358
|
|
|
* is in MultiLine text mode. |
|
359
|
|
|
* @param THtmlWriter $writer the writer used for the rendering purpose^M |
|
360
|
|
|
*/ |
|
361
|
|
|
public function renderBeginTag($writer) |
|
362
|
|
|
{ |
|
363
|
|
|
parent::renderBeginTag($writer); |
|
364
|
|
|
if ($this->getTextMode() === 'MultiLine') { |
|
365
|
|
|
$writer->write("\n"); |
|
366
|
|
|
} |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
/** |
|
370
|
|
|
* @return TTextBoxAutoCompleteType the AutoComplete type of the textbox |
|
371
|
|
|
*/ |
|
372
|
|
|
public function getAutoCompleteType() |
|
373
|
|
|
{ |
|
374
|
|
|
return $this->getViewState('AutoCompleteType', TTextBoxAutoCompleteType::None); |
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
/** |
|
378
|
|
|
* @param TTextBoxAutoCompleteType $value the AutoComplete type of the textbox, default value is TTextBoxAutoCompleteType::None. |
|
379
|
|
|
* @throws TInvalidDataValueException if the input parameter is not a valid AutoComplete type |
|
380
|
|
|
*/ |
|
381
|
|
|
public function setAutoCompleteType($value) |
|
382
|
|
|
{ |
|
383
|
|
|
$this->setViewState('AutoCompleteType', TPropertyValue::ensureEnum($value, 'TTextBoxAutoCompleteType'), TTextBoxAutoCompleteType::None); |
|
384
|
|
|
} |
|
385
|
|
|
|
|
386
|
|
|
/** |
|
387
|
|
|
* @return bool a value indicating whether an automatic postback to the server |
|
388
|
|
|
* will occur whenever the user modifies the text in the TTextBox control and |
|
389
|
|
|
* then tabs out of the component. Defaults to false. |
|
390
|
|
|
*/ |
|
391
|
|
|
public function getAutoPostBack() |
|
392
|
|
|
{ |
|
393
|
|
|
return $this->getViewState('AutoPostBack', false); |
|
394
|
|
|
} |
|
395
|
|
|
|
|
396
|
|
|
/** |
|
397
|
|
|
* Sets the value indicating if postback automatically. |
|
398
|
|
|
* An automatic postback to the server will occur whenever the user |
|
399
|
|
|
* modifies the text in the TTextBox control and then tabs out of the component. |
|
400
|
|
|
* @param bool $value the value indicating if postback automatically |
|
401
|
|
|
*/ |
|
402
|
|
|
public function setAutoPostBack($value) |
|
403
|
|
|
{ |
|
404
|
|
|
$this->setViewState('AutoPostBack', TPropertyValue::ensureBoolean($value), false); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
/** |
|
408
|
|
|
* @return bool a value indicating whether the input text should be trimmed spaces. Defaults to false. |
|
409
|
|
|
*/ |
|
410
|
|
|
public function getAutoTrim() |
|
411
|
|
|
{ |
|
412
|
|
|
return $this->getViewState('AutoTrim', false); |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
/** |
|
416
|
|
|
* Sets the value indicating if the input text should be trimmed spaces |
|
417
|
|
|
* @param bool $value the value indicating if the input text should be trimmed spaces |
|
418
|
|
|
*/ |
|
419
|
|
|
public function setAutoTrim($value) |
|
420
|
|
|
{ |
|
421
|
|
|
$this->setViewState('AutoTrim', TPropertyValue::ensureBoolean($value), false); |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
/** |
|
425
|
|
|
* @return bool whether postback event trigger by this text box will cause input validation, default is true. |
|
426
|
|
|
*/ |
|
427
|
|
|
public function getCausesValidation() |
|
428
|
|
|
{ |
|
429
|
|
|
return $this->getViewState('CausesValidation', true); |
|
430
|
|
|
} |
|
431
|
|
|
|
|
432
|
|
|
/** |
|
433
|
|
|
* @param bool $value whether postback event trigger by this text box will cause input validation. |
|
434
|
|
|
*/ |
|
435
|
|
|
public function setCausesValidation($value) |
|
436
|
|
|
{ |
|
437
|
|
|
$this->setViewState('CausesValidation', TPropertyValue::ensureBoolean($value), true); |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
/** |
|
441
|
|
|
* @return int the display width of the text box in characters, default is 0 meaning not set. |
|
442
|
|
|
*/ |
|
443
|
|
|
public function getColumns() |
|
444
|
|
|
{ |
|
445
|
|
|
return $this->getViewState('Columns', 0); |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
/** |
|
449
|
|
|
* Sets the display width of the text box in characters. |
|
450
|
|
|
* @param int $value the display width, set it 0 to clear the setting |
|
451
|
|
|
*/ |
|
452
|
|
|
public function setColumns($value) |
|
453
|
|
|
{ |
|
454
|
|
|
$this->setViewState('Columns', TPropertyValue::ensureInteger($value), 0); |
|
455
|
|
|
} |
|
456
|
|
|
|
|
457
|
|
|
/** |
|
458
|
|
|
* @return int the maximum number of characters allowed in the text box, default is 0 meaning not set. |
|
459
|
|
|
*/ |
|
460
|
|
|
public function getMaxLength() |
|
461
|
|
|
{ |
|
462
|
|
|
return $this->getViewState('MaxLength', 0); |
|
463
|
|
|
} |
|
464
|
|
|
|
|
465
|
|
|
/** |
|
466
|
|
|
* Sets the maximum number of characters allowed in the text box. |
|
467
|
|
|
* @param int $value the maximum length, set it 0 to clear the setting |
|
468
|
|
|
*/ |
|
469
|
|
|
public function setMaxLength($value) |
|
470
|
|
|
{ |
|
471
|
|
|
$this->setViewState('MaxLength', TPropertyValue::ensureInteger($value), 0); |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
/** |
|
475
|
|
|
* @return bool whether the textbox is read only, default is false. |
|
476
|
|
|
*/ |
|
477
|
|
|
public function getReadOnly() |
|
478
|
|
|
{ |
|
479
|
|
|
return $this->getViewState('ReadOnly', false); |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* @param bool $value whether the textbox is read only |
|
484
|
|
|
*/ |
|
485
|
|
|
public function setReadOnly($value) |
|
486
|
|
|
{ |
|
487
|
|
|
$this->setViewState('ReadOnly', TPropertyValue::ensureBoolean($value), false); |
|
488
|
|
|
} |
|
489
|
|
|
|
|
490
|
|
|
/** |
|
491
|
|
|
* @return int the number of rows displayed in a multiline text box, default is 4 |
|
492
|
|
|
*/ |
|
493
|
|
|
public function getRows() |
|
494
|
|
|
{ |
|
495
|
|
|
return $this->getViewState('Rows', self::DEFAULT_ROWS); |
|
496
|
|
|
} |
|
497
|
|
|
|
|
498
|
|
|
/** |
|
499
|
|
|
* Sets the number of rows displayed in a multiline text box. |
|
500
|
|
|
* @param int $value the number of rows |
|
501
|
|
|
*/ |
|
502
|
|
|
public function setRows($value) |
|
503
|
|
|
{ |
|
504
|
|
|
$this->setViewState('Rows', TPropertyValue::ensureInteger($value), self::DEFAULT_ROWS); |
|
505
|
|
|
} |
|
506
|
|
|
|
|
507
|
|
|
/** |
|
508
|
|
|
* @return bool whether password should be displayed in the textbox during postback. Defaults to false. This property only applies when TextMode='Password'. |
|
509
|
|
|
*/ |
|
510
|
|
|
public function getPersistPassword() |
|
511
|
|
|
{ |
|
512
|
|
|
return $this->getViewState('PersistPassword', false); |
|
513
|
|
|
} |
|
514
|
|
|
|
|
515
|
|
|
/** |
|
516
|
|
|
* @param bool $value whether password should be displayed in the textbox during postback. This property only applies when TextMode='Password'. |
|
517
|
|
|
*/ |
|
518
|
|
|
public function setPersistPassword($value) |
|
519
|
|
|
{ |
|
520
|
|
|
$this->setViewState('PersistPassword', TPropertyValue::ensureBoolean($value), false); |
|
521
|
|
|
} |
|
522
|
|
|
|
|
523
|
|
|
/** |
|
524
|
|
|
* @return string the text content of the TTextBox control. |
|
525
|
|
|
*/ |
|
526
|
|
|
public function getText() |
|
527
|
|
|
{ |
|
528
|
|
|
return $this->getViewState('Text', ''); |
|
529
|
|
|
} |
|
530
|
|
|
|
|
531
|
|
|
/** |
|
532
|
|
|
* Sets the text content of the TTextBox control. |
|
533
|
|
|
* @param string $value the text content |
|
534
|
|
|
*/ |
|
535
|
|
|
public function setText($value) |
|
536
|
|
|
{ |
|
537
|
|
|
$this->setViewState('Text', TPropertyValue::ensureString($value), ''); |
|
538
|
|
|
$this->_safeText = null; |
|
539
|
|
|
} |
|
540
|
|
|
|
|
541
|
|
|
/** |
|
542
|
|
|
* Returns the text content of the TTextBox control. |
|
543
|
|
|
* This method is required by {@link \Prado\IDataRenderer}. |
|
544
|
|
|
* It is the same as {@link getText()}. |
|
545
|
|
|
* @return string the text content of the TTextBox control. |
|
546
|
|
|
* @see getText |
|
547
|
|
|
* @since 3.1.0 |
|
548
|
|
|
*/ |
|
549
|
|
|
public function getData() |
|
550
|
|
|
{ |
|
551
|
|
|
return $this->getText(); |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
/** |
|
555
|
|
|
* Sets the text content of the TTextBox control. |
|
556
|
|
|
* This method is required by {@link \Prado\IDataRenderer}. |
|
557
|
|
|
* It is the same as {@link setText()}. |
|
558
|
|
|
* @param string $value the text content of the TTextBox control. |
|
559
|
|
|
* @see setText |
|
560
|
|
|
* @since 3.1.0 |
|
561
|
|
|
*/ |
|
562
|
|
|
public function setData($value) |
|
563
|
|
|
{ |
|
564
|
|
|
$this->setText($value); |
|
565
|
|
|
} |
|
566
|
|
|
|
|
567
|
|
|
/** |
|
568
|
|
|
* @return string safe text content with javascript stripped off |
|
569
|
|
|
*/ |
|
570
|
|
|
public function getSafeText() |
|
571
|
|
|
{ |
|
572
|
|
|
if ($this->_safeText === null) { |
|
573
|
|
|
$this->_safeText = $this->getSafeTextParser()->purify($this->getText()); |
|
|
|
|
|
|
574
|
|
|
} |
|
575
|
|
|
return $this->_safeText; |
|
576
|
|
|
} |
|
577
|
|
|
|
|
578
|
|
|
/** |
|
579
|
|
|
* @return \HTMLPurifier safe text parser |
|
580
|
|
|
*/ |
|
581
|
|
|
protected function getSafeTextParser() |
|
582
|
|
|
{ |
|
583
|
|
|
if (!self::$_safeTextParser) { |
|
584
|
|
|
self::$_safeTextParser = new \HTMLPurifier($this->getConfig()); |
|
585
|
|
|
} |
|
586
|
|
|
return self::$_safeTextParser; |
|
587
|
|
|
} |
|
588
|
|
|
|
|
589
|
|
|
/** |
|
590
|
|
|
* @return TTextBoxMode the behavior mode of the TTextBox component. Defaults to TTextBoxMode::SingleLine. |
|
591
|
|
|
*/ |
|
592
|
|
|
public function getTextMode() |
|
593
|
|
|
{ |
|
594
|
|
|
return $this->getViewState('TextMode', TTextBoxMode::SingleLine); |
|
595
|
|
|
} |
|
596
|
|
|
|
|
597
|
|
|
/** |
|
598
|
|
|
* Sets the behavior mode of the TTextBox component. |
|
599
|
|
|
* @param TTextBoxMode $value the text mode |
|
600
|
|
|
* @throws TInvalidDataValueException if the input value is not a valid text mode. |
|
601
|
|
|
*/ |
|
602
|
|
|
public function setTextMode($value) |
|
603
|
|
|
{ |
|
604
|
|
|
$this->setViewState('TextMode', TPropertyValue::ensureEnum($value, 'TTextBoxMode'), TTextBoxMode::SingleLine); |
|
605
|
|
|
} |
|
606
|
|
|
|
|
607
|
|
|
/** |
|
608
|
|
|
* @return string the group of validators which the text box causes validation upon postback |
|
609
|
|
|
*/ |
|
610
|
|
|
public function getValidationGroup() |
|
611
|
|
|
{ |
|
612
|
|
|
return $this->getViewState('ValidationGroup', ''); |
|
613
|
|
|
} |
|
614
|
|
|
|
|
615
|
|
|
/** |
|
616
|
|
|
* @param string $value the group of validators which the text box causes validation upon postback |
|
617
|
|
|
*/ |
|
618
|
|
|
public function setValidationGroup($value) |
|
619
|
|
|
{ |
|
620
|
|
|
$this->setViewState('ValidationGroup', $value, ''); |
|
621
|
|
|
} |
|
622
|
|
|
|
|
623
|
|
|
/** |
|
624
|
|
|
* @return bool whether the text content wraps within a multiline text box. Defaults to true. |
|
625
|
|
|
*/ |
|
626
|
|
|
public function getWrap() |
|
627
|
|
|
{ |
|
628
|
|
|
return $this->getViewState('Wrap', true); |
|
629
|
|
|
} |
|
630
|
|
|
|
|
631
|
|
|
/** |
|
632
|
|
|
* Sets the value indicating whether the text content wraps within a multiline text box. |
|
633
|
|
|
* @param bool $value whether the text content wraps within a multiline text box. |
|
634
|
|
|
*/ |
|
635
|
|
|
public function setWrap($value) |
|
636
|
|
|
{ |
|
637
|
|
|
$this->setViewState('Wrap', TPropertyValue::ensureBoolean($value), true); |
|
638
|
|
|
} |
|
639
|
|
|
|
|
640
|
|
|
/** |
|
641
|
|
|
* Sets a custom configuration for HTMLPurifier. |
|
642
|
|
|
* @param \HTMLPurifier_Config $value custom configuration |
|
643
|
|
|
*/ |
|
644
|
|
|
public function setConfig(\HTMLPurifier_Config $value) |
|
645
|
|
|
{ |
|
646
|
|
|
$this->setViewState('Config', $value, null); |
|
647
|
|
|
} |
|
648
|
|
|
|
|
649
|
|
|
/** |
|
650
|
|
|
* @return \HTMLPurifier_Config Configuration for HTMLPurifier. |
|
651
|
|
|
*/ |
|
652
|
|
|
public function getConfig() |
|
653
|
|
|
{ |
|
654
|
|
|
$config = $this->getViewState('Config', null); |
|
655
|
|
|
return ($config === null) ? \HTMLPurifier_Config::createDefault() : $config; |
|
656
|
|
|
} |
|
657
|
|
|
} |
|
658
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.