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 {
34 var $mOnKeyPress = "";
36 function __construct($name)
38 $this->class = 'TextArea';
42 function setColumns($value) { $this->mColumns = $value; }
43 function getColumns() { return $this->mColumns; }
45 function setRows($value) { $this->mRows = $value; }
46 function getRows() { return $this->mRows; }
50 if ($this->id=="") $this->id = $this->mName;
54 $html = "\n\t<textarea";
55 $html .= " name=\"$this->name\" id=\"$this->id\"";
57 if ($this->mColumns!="")
58 $html .= " cols=\"$this->mColumns\"";
61 $html .= " rows=\"$this->mRows\"";
63 if ($this->max_length!="") {
64 if ($this->mOnKeyPress) $this->mOnKeyPress .= ";";
65 $this->mOnKeyPress .= "return validateMaxLenght_".$this->name."(this, event);";
66 $js_maxlen = $this->getExtraScript();
67 $html .= " maxlength=\"$this->max_length\"";
71 $html .= " style=\"$this->style\"";
73 if ($this->mOnKeyPress) {
74 $html .= " onkeypress=\"$this->mOnKeyPress\"";
77 $html .= ">".htmlspecialchars($this->getValue())."</textarea>";
78 if ($js_maxlen) $html = $js_maxlen."\n".$html;
83 function getExtraScript() {
85 $s .= "var isNS4 = (navigator.appName==\"Netscape\")?1:0;\n";
86 $s .= "function validateMaxLenght_".$this->name."(element, event) {\n";
87 $s .= "\tmaxlength=".$this->max_length.";\n";
88 $s .= "\tvar iKey = (!isNS4?event.keyCode:event.which);\n";
89 //$s .= "alert(iKey);";
90 $s .= "\tvar re = new RegExp(\"".'\r\n'."\",\"g\");\n";
91 $s .= "\tvar x = element.value.replace(re,\"\").length;\n";
92 $s .= "\tif ((x>=maxlength) && ((iKey > 31 && iKey < 1200) || (iKey > 95 && iKey < 106)) && (iKey != 13)) {\n";
93 $s .= "\t\treturn false;\n";
95 $s .= "\t\treturn true;\n";