1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\collections\form; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
use Ajax\semantic\html\base\constants\Wide; |
7
|
|
|
use Ajax\semantic\html\base\constants\State; |
8
|
|
|
|
9
|
|
|
class HtmlFormField extends HtmlSemDoubleElement { |
10
|
|
|
protected $_container; |
11
|
|
|
public function __construct($identifier, $field,$label=NULL) { |
12
|
|
|
parent::__construct($identifier, "div","field"); |
13
|
|
|
$this->content=array(); |
14
|
|
|
$this->_states=[State::ERROR,State::DISABLED]; |
15
|
|
|
if(isset($label)) |
16
|
|
|
$this->setLabel($label); |
17
|
|
|
$this->setField($field); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function setLabel($label){ |
21
|
|
|
$labelO=$label; |
22
|
|
|
if(\is_string($label)){ |
23
|
|
|
$labelO=new HtmlSemDoubleElement("","label"); |
24
|
|
|
$labelO->setContent($label); |
25
|
|
|
$labelO->setProperty("for", \str_replace("field-", "",$this->identifier)); |
26
|
|
|
} |
27
|
|
|
$this->content["label"]=$labelO; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function setField($field){ |
31
|
|
|
$this->content["field"]=$field; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Returns the label or null |
36
|
|
|
* @return mixed |
37
|
|
|
*/ |
38
|
|
|
public function getLabel(){ |
39
|
|
|
if(\array_key_exists("label", $this->content)) |
40
|
|
|
return $this->content["label"]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Return the field |
45
|
|
|
* @return mixed |
46
|
|
|
*/ |
47
|
|
|
public function getField(){ |
48
|
|
|
return $this->content["field"]; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* puts the label before or behind |
53
|
|
|
*/ |
54
|
|
|
public function swapLabel(){ |
55
|
|
|
$label=$this->getLabel(); |
56
|
|
|
unset($this->content["label"]); |
57
|
|
|
$this->content["label"]=$label; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Defines the field width |
62
|
|
|
* @param int $width |
63
|
|
|
* @return \Ajax\semantic\html\collections\form\HtmlFormField |
64
|
|
|
*/ |
65
|
|
|
public function setWidth($width){ |
66
|
|
|
if(\is_int($width)){ |
67
|
|
|
$width=Wide::getConstants()["W".$width]; |
68
|
|
|
} |
69
|
|
|
$this->addToPropertyCtrl("class", $width, Wide::getConstants()); |
70
|
|
|
if(isset($this->_container)){ |
71
|
|
|
$this->_container->setEqualWidth(false); |
72
|
|
|
} |
73
|
|
|
return $this->addToPropertyCtrl("class", "wide",array("wide")); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Field displays an error state |
78
|
|
|
* @return \Ajax\semantic\html\collections\form\HtmlFormField |
79
|
|
|
*/ |
80
|
|
|
public function setError(){ |
81
|
|
|
return $this->addToProperty("class", "error"); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function jsState($state){ |
85
|
|
|
return $this->jsDoJquery("addClass",$state); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function setContainer($_container) { |
89
|
|
|
$this->_container=$_container; |
90
|
|
|
return $this; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function setReadonly(){ |
94
|
|
|
$this->getField()->setProperty("readonly", ""); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |