phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlFormFields.php
Go to the documentation of this file.
1<?php
2
4
8
11
13 protected $_equalWidth;
14 protected $_name;
15
16 public function __construct($identifier, $fields=array(), $equalWidth=true) {
17 parent::__construct($identifier, "div");
18 $this->_equalWidth=$equalWidth;
19 $this->addItems($fields);
20 }
21
22 public function addFields($fields=NULL, $label=NULL) {
23 if (!$fields instanceof HtmlFormFields) {
24 if (!\is_array($fields)) {
25 $fields=\func_get_args();
26 $end=\end($fields);
27 if (\is_string($end)) {
28 $label=$end;
29 \array_pop($fields);
30 } else
31 $label=NULL;
32 }
33 }
34 if (isset($label))
35 $this->setLabel($label);
36 foreach ( $fields as $field ) {
37 $this->addItem($field);
38 }
39 return $this;
40 }
41
47 public function setLabel($label) {
48 $labelO=$label;
49 if (\is_string($label)) {
50 $labelO=new HtmlSemDoubleElement("", "label", "", $label);
51 }
52 $this->insertItem($labelO, 0);
53 return $labelO;
54 }
55
56 public function addItem($item) {
57 $item=parent::addItem($item);
58 if($item instanceof HtmlFormField)
59 $item->setContainer($this);
60 return $item;
61 }
62
66 public function getItem($index){
67 return parent::getItem($index);
68 }
69
70 public function compile(JsUtils $js=NULL, &$view=NULL) {
71 if ($this->_equalWidth) {
72 $count=$this->count();
73 $this->addToProperty("class", Wide::getConstants()["W".$count]." fields");
74 } else
75 $this->addToProperty("class", "fields");
76 return parent::compile($js, $view);
77 }
78
79 public function setWidth($index, $width) {
80 $this->_equalWidth=false;
81 return $this->getItem($index)->setWidth($width);
82 }
83
84 public function setInline() {
85 $this->_equalWidth=false;
86 $this->addToProperty("class", "inline");
87 return $this;
88 }
89
90 public function setGrouped() {
91 $this->_equalWidth=false;
92 $this->addToProperty("class", "grouped");
93 }
94
95 public function getName() {
96 return $this->_name;
97 }
98
99 public function setName($_name) {
100 $this->_name=$_name;
101 return $this;
102 }
103
104
105 public static function radios($identifier,$name, $items=array(), $label=NULL, $value=null, $type=NULL) {
106 $fields=array ();
107 $i=0;
108 foreach ( $items as $val => $caption ) {
109 $itemO=new HtmlFormRadio($name."-".$i++, $name, $caption, $val, $type);
110 if ($val===$value) {
111 $itemO->getDataField()->setProperty("checked", "");
112 }
113 $fields[]=$itemO;
114 }
115 $radios=new HtmlFormFields($identifier, $fields);
116 if (isset($label)){
117 $lbl=$radios->setLabel($label);
118 if($lbl instanceof HtmlSemDoubleElement){
119 $lbl->setProperty("for", $name);
120 }
121 }
122 return $radios;
123 }
124
125 public static function checkeds($identifier,$name, $items=array(), $label=NULL, $values=array(), $type=NULL) {
126 $fields=array ();
127 $i=0;
128 foreach ( $items as $val => $caption ) {
129 $itemO=new HtmlFormCheckbox($name."-".$i++, $caption, $val, $type);
130 $itemO->setName($name);
131 if (\array_search($val, $values)!==false) {
132 $itemO->getDataField()->setProperty("checked", "");
133 }
134 $fields[]=$itemO;
135 }
136 $radios=new HtmlFormFields($identifier, $fields);
137 if (isset($label))
138 $radios->setLabel($label)->setProperty("for", $name);
139 return $radios;
140 }
141
142 public function setEqualWidth($_equalWidth) {
143 $this->_equalWidth=$_equalWidth;
144 return $this;
145 }
146
147 public function run(JsUtils $js){
148 return parent::run($js);
149 //return $result->setItemSelector("[data-value]");
150 }
151}
JQuery PHP library.
Definition JsUtils.php:23
Base class for Semantic Html collections.
Base class for Semantic double elements.
addToProperty($name, $value, $separator=" ")
run(JsUtils $js)
SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\Bas...
static radios($identifier, $name, $items=array(), $label=NULL, $value=null, $type=NULL)
__construct($identifier, $fields=array(), $equalWidth=true)
static checkeds($identifier, $name, $items=array(), $label=NULL, $values=array(), $type=NULL)