phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlFormField.php
Go to the documentation of this file.
1<?php
3
14
16
17 protected $_container;
18
19 protected $_validation;
20
21 public function __construct($identifier, $field, $label = NULL) {
22 parent::__construct($identifier, "div", "field");
23 $this->content = array();
24 $this->_states = [
25 State::ERROR,
26 State::DISABLED
27 ];
28 if (isset($label) && $label !== "")
29 $this->setLabel($label);
30 $this->setField($field);
31 $this->_validation = NULL;
32 }
33
34 public function addPointingLabel($label, $pointing = Direction::NONE) {
35 $labelO = new HtmlLabel("", $label);
36 $labelO->setPointing($pointing);
37 $this->addContent($labelO, $pointing === "below" || $pointing === "right");
38 return $labelO;
39 }
40
41 public function setLabel($label) {
42 $labelO = $label;
43 if (\is_string($label)) {
44 $labelO = new HtmlSemDoubleElement("", "label", "");
45 $labelO->setContent($label);
46 $labelO->setProperty("for", \str_replace("field-", "", $this->identifier));
47 }
48 $this->content["label"] = $labelO;
49 }
50
51 public function setField($field) {
52 $this->content["field"] = $field;
53 }
54
60 public function getLabel() {
61 if (\array_key_exists("label", $this->content))
62 return $this->content["label"];
63 }
64
70 public function getField() {
71 return $this->content["field"];
72 }
73
79 public function getDataField() {
80 return $this->content["field"];
81 }
82
86 public function swapLabel() {
87 $label = $this->getLabel();
88 unset($this->content["label"]);
89 $this->content["label"] = $label;
90 }
91
98 public function setWidth($width) {
99 if (\is_int($width)) {
100 $width = Wide::getConstants()["W" . $width];
101 }
102 $this->addToPropertyCtrl("class", $width, Wide::getConstants());
103 if (isset($this->_container)) {
104 $this->_container->setEqualWidth(false);
105 }
106 return $this->addToPropertyCtrl("class", "wide", array(
107 "wide"
108 ));
109 }
110
116 public function setError() {
117 return $this->addToProperty("class", "error");
118 }
119
120 public function setInline() {
121 return $this->addToProperty("class", "inline");
122 }
123
124 public function jsState($state) {
125 return $this->jsDoJquery("addClass", $state);
126 }
127
128 public function setContainer($_container) {
129 $this->_container = $_container;
130 return $this;
131 }
132
133 public function setReadonly() {
134 $this->getDataField()->setProperty("readonly", "");
135 }
136
137 public function addRule($type, $prompt = NULL, $value = NULL) {
138 $field = $this->getDataField();
139 if (isset($field)) {
140 if (! isset($this->_validation)) {
141 $this->_validation = new FieldValidation($field->getIdentifier());
142 }
143 if($type instanceof Rule){
144 if($type->getType()=='empty'){
145 $this->addToProperty('class', 'required');
146 }
147 }elseif ($type === 'empty' || ($type['type'] ?? '') === 'empty') {
148 $this->addToProperty('class', 'required');
149 }
150 $this->_validation->addRule($type, $prompt, $value);
151 }
152 return $this;
153 }
154
155 public function setOptional($optional = true) {
156 $field = $this->getDataField();
157 if (isset($field)) {
158 if (! isset($this->_validation)) {
159 $this->_validation = new FieldValidation($field->getIdentifier());
160 }
161 $this->_validation->setOptional($optional);
162 }
163 }
164
165 public function addRules(array $rules) {
166 foreach ($rules as $rule) {
167 $this->addRule($rule);
168 }
169 return $this;
170 }
171
172 public function setRules(array $rules) {
173 $this->_validation = null;
174 return $this->addRules($rules);
175 }
176
177 public function addIcon($icon, $direction = Direction::LEFT) {
178 $field = $this->getField();
179 return $field->addIcon($icon, $direction);
180 }
181
182 public function getValidation() {
183 return $this->_validation;
184 }
185
186 public function setSize($size) {
187 return $this->getField()->addToPropertyCtrl("class", $size, Size::getConstants());
188 }
189
190 public function run(JsUtils $js) {
191 if (isset($this->_validation)) {
192 $this->_validation->compile($js);
193 }
194 return parent::run($js);
195 }
196}
JQuery PHP library.
Definition JsUtils.php:23
Base class for Semantic double elements.
addToPropertyCtrl($name, $value, $typeCtrl)
addIcon($icon, $direction=Direction::LEFT)
run(JsUtils $js)
{{SimpleExtComponent\Ajax\common\html\BaseHtmlrun()\Ajax\common\html\BaseHtmlrun()}HtmlDoubleElement:...
addPointingLabel($label, $pointing=Direction::NONE)
__construct($identifier, $field, $label=NULL)
swapLabel()
puts the label before or behind
addRule($type, $prompt=NULL, $value=NULL)
Semantic Label component.
Definition HtmlLabel.php:20