Skip to content

Commit 61efd9d

Browse files
committed
Finished refactoring of the FormElement class.
1 parent a4d1c56 commit 61efd9d

18 files changed

Lines changed: 26 additions & 41 deletions

WEB-INF/lib/form/Calendar.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function toString($date="") {
222222
return $str;
223223
}
224224

225-
function toStringControl() {
225+
function getHtml() {
226226
return $this->toString();
227227
}
228228

WEB-INF/lib/form/Checkbox.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function isChecked() { return $this->mChecked; }
4545
function setData($value) { $this->mOptions = $value; }
4646
function getData() { return $this->mOptions; }
4747

48-
function toStringControl() {
48+
function getHtml() {
4949

5050
if ($this->id=="") $this->id = $this->name;
5151

WEB-INF/lib/form/CheckboxGroup.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function localize($i18n) {
6565
$this->lSelNone = $i18n->getKey('label.select_none');
6666
}
6767

68-
function toStringControl() {
68+
function getHtml() {
6969

7070
if ($this->id=="") $this->id = $this->name;
7171

WEB-INF/lib/form/Combobox.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function setDataKeys($keys) { $this->mDataKeys = $keys; $this->mDataDeep = 2; }
6565
function getDataKeys() { return $this->mDataKeys; }
6666

6767

68-
function toStringControl() {
68+
function getHtml() {
6969

7070
if ($this->id=="") $this->id = $this->name;
7171

WEB-INF/lib/form/DateField.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ function getValueSafe() {
8080
}
8181
}
8282

83-
function toStringControl() {
83+
function getHtml() {
8484

8585
if (!$this->isEnabled()) {
8686
$html = htmlspecialchars($this->getValue()).

WEB-INF/lib/form/Form.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function toStringCloseTag() {
188188
$html = "\n";
189189
foreach ($this->elements as $elname=>$el) {
190190
if (strtolower(get_class($this->elements[$elname]))=="hidden") {
191-
$html .= $this->elements[$elname]->toStringControl()."\n";
191+
$html .= $this->elements[$elname]->getHtml()."\n";
192192
}
193193
}
194194
$html .= "</form>";

WEB-INF/lib/form/FormElement.class.php

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,30 +84,15 @@ function setOnClick($str) { $this->on_click = $str; }
8484
function localize($i18n) {} // Localization occurs in derived classes and is dependent on control type.
8585
// For example, in calendar control we need to localize day and month names.
8686

87-
// TODO: refactoring ongoing down from here.
87+
// getHtml returns HTML for the element.
88+
function getHtml() { return ''; }
8889

90+
// getLabelHtml returns HTML code for element label.
91+
function getLabelHtml() { return '<label for="'.$this->id.'">'.$this->label.'</label>'; }
8992

90-
91-
92-
93-
94-
95-
96-
97-
98-
function toStringControl() {
99-
return "";
100-
}
101-
102-
function toStringLabel() {
103-
return "<label for=\"" . $this->id . "\">" . $this->label . "</label>";
104-
}
105-
106-
function toArray() {
107-
return array(
108-
"label"=>$this->toStringLabel(),
109-
"control"=>$this->toStringControl()
110-
);
111-
}
112-
93+
function toArray() {
94+
return array(
95+
'label'=>$this->getLabelHtml(),
96+
'control'=>$this->getHtml());
97+
}
11398
}

WEB-INF/lib/form/Hidden.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function __construct($name,$value="")
3737
$this->value = $value;
3838
}
3939

40-
function toStringControl() {
40+
function getHtml() {
4141

4242
if ($this->id=="") $this->id = $this->name;
4343

WEB-INF/lib/form/Submit.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function __construct($name,$value="")
3737
$this->value = $value;
3838
}
3939

40-
function toStringControl() {
40+
function getHtml() {
4141

4242
if ($this->id=="") $this->id = $this->name;
4343

WEB-INF/lib/form/Table.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ function _process() {
114114
}
115115
}
116116

117-
function toStringControl() {
117+
function getHtml() {
118118
if (!$this->mProccessed) $this->_process();
119119

120120
$html = "";

0 commit comments

Comments
 (0)