1: <?php
2:
3: /**
4: * Description of textfield
5: *
6: * @author SARTAJ
7: */
8:
9: namespace Sphp\comp\html{
10:
11: class TextArea extends \Sphp\tools\Control {
12:
13: public $maxLen = '';
14: public $minLen = '';
15: public $formName = '';
16: private $errmsg = '';
17: private $msgName = '';
18: private $req = false;
19:
20: protected function genhelpPropList() {
21: parent::genhelpPropList();
22: $this->addHelpPropFunList('setForm','Bind with Form JS Event','','$val');
23: $this->addHelpPropFunList('setMsgName','Name Display in placeholder and Error','','$val');
24: $this->addHelpPropFunList('setRequired','Can not submit Empty','','');
25: $this->addHelpPropFunList('setMaxLen','Maximum Accept Length','','$val');
26: $this->addHelpPropFunList('setMinLen','Minimum Accept Length','','$val');
27: }
28:
29: public function oninit() {
30: $this->tagName = "textarea";
31: if ($this->issubmit) {
32: $this->value = htmlentities($this->value, ENT_COMPAT, "UTF-8");
33: }
34: if($this->getAttribute("msgname") != ""){
35: $this->msgName = $this->getAttribute("msgname");
36: }
37: }
38: public function setErrMsg($msg){
39: $this->errmsg .= '<strong class="alert-danger">' . $msg . '</strong>';
40: setErr($this->name, $msg);
41: }
42:
43: public function setForm($val) {
44: $this->formName = $val;
45: }
46:
47: public function setMsgName($val) {
48: $this->msgName = $val;
49: $this->setAttribute('placeholder', $val);
50: }
51:
52: public function setRequired() {
53: if ($this->issubmit) {
54: if (strlen($this->value) < 1) {
55: $this->setErrMsg( $this->getAttribute("msgname") .' ' . "Can not submit Empty");
56: }
57: }
58: $this->req = true;
59: }
60:
61: public function setMaxLen($val) {
62: $this->maxLen = $val;
63: if ($this->issubmit) {
64: if (strlen($this->value) > $val) {
65: $this->setErrMsg( $this->getAttribute("msgname") .' ' . "Maximum Characters should not be exceed then $val");
66: }
67: }
68: }
69:
70: public function getMaxLen() {
71: return $this->maxLen;
72: }
73:
74: public function setMinLen($val) {
75: $this->minLen = $val;
76: if ($this->issubmit) {
77: if (strlen($this->getValue()) < $val) {
78: $this->setErrMsg( $this->getAttribute("msgname") .' ' . "Minimum Characters should be $val");
79: }
80: }
81: }
82:
83: public function getMinLen() {
84: return $this->minLen;
85: }
86:
87: public function onjsrender() {
88: if ($this->formName != '') {
89: if ($this->minLen != '') {
90: addFooterJSFunctionCode("{$this->formName}_submit", "{$this->name}min", "
91: ctlMins['$this->name']= Array('$this->msgName','TextArea','$this->minLen');");
92: }
93: if ($this->maxLen != '') {
94: addFooterJSFunctionCode("{$this->formName}_submit", "{$this->name}max", "
95: ctlMax['$this->name']= Array('$this->msgName','TextArea','$this->maxLen');");
96: }
97: if ($this->req) {
98: addFooterJSFunctionCode("{$this->formName}_submit", "{$this->name}req", "
99: ctlReq['$this->name']= Array('$this->msgName','TextArea');");
100: }
101: }
102: }
103:
104: public function onrender() {
105: if($this->errmsg!=""){
106: $this->setPostTag($this->errmsg);
107: }
108: if ($this->getAttribute('class') == '') {
109: $this->class = "form-control";
110: }
111: if ($this->value != '') {
112: $this->setInnerHTML($this->value);
113: }
114: $this->setAttributeDefault('rows', '10');
115: $this->setAttributeDefault('cols', '20');
116: }
117:
118: // javascript functions used by ajax control and other control
119: public function getJSValue() {
120: return "document.getElementById('$this->name').value";
121: }
122:
123: public function setJSValue($exp) {
124: return "document.getElementById('$this->name').value = $exp;";
125: }
126:
127: }
128:
129: }
130: