Skip to content

Commit 5706d26

Browse files
author
unclecheese
committed
Merge pull request #33 from phillprice/feature/label-holder-classes
Enable adding classes to input and label directly (also needs work in display-logic module)
2 parents 394c64e + 562c6f1 commit 5706d26

File tree

2 files changed

+66
-12
lines changed

2 files changed

+66
-12
lines changed

code/BootstrapFormField.php

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,24 @@ class BootstrapFormField extends DataExtension {
2020
"form-group"
2121
);
2222

23+
protected $labelClasses = array(
24+
);
25+
26+
protected $inputClasses = array(
27+
);
28+
2329

2430
/**
2531
* Adds a HTML5 placeholder attribute to the form field
26-
*
32+
*
2733
* @param $text the placeholder text to add
2834
* @return BootstrapFormField
2935
*/
3036
public function addPlaceholder($text) {
3137
return $this->owner->setAttribute("placeholder",$text);
3238
}
3339

34-
40+
3541
/**
3642
* Adds a block of help text to the form field. (HTML safe).
3743
* By default, this text appears below a field and its label.
@@ -89,21 +95,69 @@ public function HolderAttributes() {
8995
}
9096

9197
/**
92-
* Allows adding custom classes to the holder
93-
*
98+
* Allows adding custom classes to the input
99+
*
100+
* @param string $class the class
101+
*
102+
* @return BootstrapFormField
103+
*/
104+
public function addInputClass($class) {
105+
$this->inputClasses[] = $class;
106+
return $this->owner;
107+
}
108+
109+
/**
110+
* returns the input classes to be used in templates
111+
* also triggers checking for error messages
112+
*
113+
* @return string of classes
114+
*/
115+
public function InputClasses() {
116+
$this->loadErrorMessage();
117+
118+
return implode(" ",$this->inputClasses);
119+
}
120+
121+
/**
122+
* Allows adding custom classes to the label
123+
*
124+
* @param string $class the class
125+
*
126+
* @return BootstrapFormField
127+
*/
128+
public function addLabelClass($class) {
129+
$this->labelClasses[] = $class;
130+
return $this->owner;
131+
}
132+
133+
/**
134+
* returns the label classes to be used in templates
135+
* also triggers checking for error messages
136+
*
137+
* @return string of classes
138+
*/
139+
public function LabelClasses() {
140+
$this->loadErrorMessage();
141+
142+
return implode(" ",$this->labelClasses);
143+
}
144+
145+
/**
146+
* Allows adding custom classes to the holder
147+
*
94148
* @param string $class the class
95-
*
149+
*
96150
* @return BootstrapFormField
97151
*/
98-
public function addHolderClass($class) {
152+
public function addHolderClass($class) {
99153
$this->holderClasses[] = $class;
100154
return $this->owner;
101155
}
102156

103157
/**
104158
* returns the holder classes to be used in templates
105159
* also triggers checking for error messages
106-
*
160+
*
107161
* @return string of classes
108162
*/
109163
public function HolderClasses() {
@@ -127,7 +181,7 @@ public function onBeforeRender() {
127181
/**
128182
* checks for error messages in owner form field
129183
* adds error class to holder and loads error message as helptext
130-
*
184+
*
131185
* @todo allow setting error message as inline
132186
*/
133187
private function loadErrorMessage() {
@@ -136,5 +190,5 @@ private function loadErrorMessage() {
136190
$this->addHelpText($this->owner->message);
137191
}
138192
}
139-
193+
140194
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<div id="$Name" class="checkbox $HolderClasses" $HolderAttributes>
2-
<label>
3-
<input $AttributesHTML>
2+
<label class="$labelClasses">
43
$Title
4+
<input $AttributesHTML class="$inputClasses">
55
</label>
66
<% if $HelpText %>
77
<p class="help-block">$HelpText</p>
88
<% end_if %>
99
<% if $InlineHelpText %>
1010
<span class="help-inline">$InlineHelpText</span>
11-
<% end_if %>
11+
<% end_if %>
1212
</div>
1313

0 commit comments

Comments
 (0)