2 // +----------------------------------------------------------------------+
3 // | Anuko Time Tracker
4 // +----------------------------------------------------------------------+
5 // | Copyright (c) Anuko International Ltd. (https://www.anuko.com)
6 // +----------------------------------------------------------------------+
7 // | LIBERAL FREEWARE LICENSE: This source code document may be used
8 // | by anyone for any purpose, and freely redistributed alone or in
9 // | combination with other software, provided that the license is obeyed.
11 // | There are only two ways to violate the license:
13 // | 1. To redistribute this code in source form, with the copyright
14 // | notice or license removed or altered. (Distributing in compiled
15 // | forms without embedded copyright notices is permitted).
17 // | 2. To redistribute modified versions of this code in *any* form
18 // | that bears insufficient indications that the modifications are
19 // | not the work of the original author(s).
21 // | This license applies to this document only, not any other software
22 // | that it may be combined with.
24 // +----------------------------------------------------------------------+
26 // | https://www.anuko.com/time_tracker/credits.htm
27 // +----------------------------------------------------------------------+
29 import('form.FormElement');
31 class TextArea extends FormElement {
33 var $mPassword = false;
36 var $cClassName = "TextArea";
38 function __construct($name,$value="")
41 $this->mValue = $value;
44 function setColumns($value) { $this->mColumns = $value; }
45 function getColumns() { return $this->mColumns; }
47 function setRows($value) { $this->mRows = $value; }
48 function getRows() { return $this->mRows; }
50 function toStringControl() {
51 if (!$this->isRenderable()) return "";
53 if ($this->mId=="") $this->mId = $this->mName;
57 $html = "\n\t<textarea";
58 $html .= " name=\"$this->mName\" id=\"$this->mId\"";
60 if ($this->mColumns!="")
61 $html .= " cols=\"$this->mColumns\"";
64 $html .= " rows=\"$this->mRows\"";
66 if ($this->mMaxLength!="") {
67 if ($this->mOnKeyPress) $this->mOnKeyPress .= ";";
68 $this->mOnKeyPress .= "return validateMaxLenght_".$this->mName."(this, event);";
69 $js_maxlen = $this->getExtraScript();
70 $html .= " maxlength=\"$this->mMaxLength\"";
73 if ($this->mStyle!="")
74 $html .= " style=\"$this->mStyle\"";
76 if ($this->mOnKeyPress) {
77 $html .= " onkeypress=\"$this->mOnKeyPress\"";
80 $html .= ">".htmlspecialchars($this->getValue())."</textarea>";
81 if ($js_maxlen) $html = $js_maxlen."\n".$html;
86 function getExtraScript() {
88 $s .= "var isNS4 = (navigator.appName==\"Netscape\")?1:0;\n";
89 $s .= "function validateMaxLenght_".$this->mName."(element, event) {\n";
90 $s .= "\tmaxlength=".$this->mMaxLength.";\n";
91 $s .= "\tvar iKey = (!isNS4?event.keyCode:event.which);\n";
92 //$s .= "alert(iKey);";
93 $s .= "\tvar re = new RegExp(\"".'\r\n'."\",\"g\");\n";
94 $s .= "\tvar x = element.value.replace(re,\"\").length;\n";
95 $s .= "\tif ((x>=maxlength) && ((iKey > 31 && iKey < 1200) || (iKey > 95 && iKey < 106)) && (iKey != 13)) {\n";
96 $s .= "\t\treturn false;\n";
98 $s .= "\t\treturn true;\n";