|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\collections\form; |
|
4
|
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemCollection; |
|
6
|
|
|
use Ajax\semantic\html\elements\HtmlHeader; |
|
7
|
|
|
/** |
|
8
|
|
|
* Semantic Form component |
|
9
|
|
|
* @see http://semantic-ui.com/collections/form.html |
|
10
|
|
|
* @author jc |
|
11
|
|
|
* @version 1.001 |
|
12
|
|
|
*/ |
|
13
|
|
|
class HtmlForm extends HtmlSemCollection{ |
|
14
|
|
|
|
|
15
|
|
|
use FieldsTrait; |
|
16
|
|
|
|
|
17
|
|
|
protected $_fields; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct( $identifier, $elements=array()){ |
|
20
|
|
|
parent::__construct( $identifier, "form", "ui form"); |
|
21
|
|
|
$this->setProperty("name", $this->identifier); |
|
22
|
|
|
$this->_fields=array(); |
|
23
|
|
|
$this->addItems($elements); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function addHeader($title,$niveau=1,$dividing=true){ |
|
27
|
|
|
$header=new HtmlHeader("",$niveau,$title); |
|
28
|
|
|
if($dividing) |
|
29
|
|
|
$header->setDividing(); |
|
30
|
|
|
return $this->addItem($header); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function addFields($fields,$label=NULL){ |
|
34
|
|
|
if(!$fields instanceof HtmlFormFields){ |
|
35
|
|
|
if(\is_array($fields)===false){ |
|
36
|
|
|
$fields = \func_get_args(); |
|
37
|
|
|
$end=\end($fields); |
|
38
|
|
|
if(\is_string($end)){ |
|
39
|
|
|
$label=$end; |
|
40
|
|
|
\array_pop($fields); |
|
41
|
|
|
}else $label=NULL; |
|
42
|
|
|
} |
|
43
|
|
|
$this->_fields=\array_merge($this->_fields,$fields); |
|
44
|
|
|
$fields=new HtmlFormFields("fields-".$this->identifier."-".$this->count(),$fields); |
|
45
|
|
|
} |
|
46
|
|
|
if(isset($label)) |
|
47
|
|
|
$fields=new HtmlFormField("", $fields,$label); |
|
48
|
|
|
$this->addItem($fields); |
|
49
|
|
|
return $fields; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function addItem($item){ |
|
53
|
|
|
$item=parent::addItem($item); |
|
54
|
|
|
if(\is_subclass_of($item, HtmlFormField::class)===true){ |
|
55
|
|
|
$this->_fields[]=$item; |
|
56
|
|
|
} |
|
57
|
|
|
return $item; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getField($index){ |
|
61
|
|
|
if(\is_string($index)){ |
|
62
|
|
|
$field=$this->getElementById($index, $this->_fields); |
|
63
|
|
|
}else{ |
|
64
|
|
|
$field=$this->_fields[$index]; |
|
65
|
|
|
} |
|
66
|
|
|
return $field; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* automatically divide fields to be equal width |
|
71
|
|
|
* @return \Ajax\semantic\html\collections\form\HtmlForm |
|
72
|
|
|
*/ |
|
73
|
|
|
public function setEqualWidth(){ |
|
74
|
|
|
return $this->addToProperty("class", "equal width"); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Adds a field (alias for addItem) |
|
79
|
|
|
* @param HtmlFormField $field |
|
80
|
|
|
* @return \Ajax\common\html\HtmlDoubleElement |
|
81
|
|
|
*/ |
|
82
|
|
|
public function addField($field){ |
|
83
|
|
|
return $this->addItem($field); |
|
84
|
|
|
} |
|
85
|
|
|
} |