Skip to content
This repository

Set the CSS class for JForm field label #1169

Merged
merged 3 commits into from almost 2 years ago

2 participants

Viet Hoang Vu Louis Landry
Viet Hoang Vu

This pull is intended to allow developer to set CSS class for form field's label. It can be useful for styling purpose.

For example Twitter Bootstrap requires class="control-label" for form field label tag.

Usage: add labelclass="your-css-class" in your form xml manifest

<......description="" required="true" labelclass="control-label" />

Louis Landry

Just a few code style issues to clean up and we can get this merged. Thanks!

http://developer.joomla.org/pulls/pulls/1169.html

Viet Hoang Vu

Just fixed some tab issues.

Louis Landry LouisLandry merged commit 18070dd into from April 26, 2012
Louis Landry LouisLandry closed this April 26, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 13 additions and 0 deletions. Show diff stats Hide diff stats

  1. 13  libraries/joomla/form/field.php
13  libraries/joomla/form/field.php
@@ -166,6 +166,14 @@
166 166
 	protected $value;
167 167
 
168 168
 	/**
  169
+	 * The label's CSS class of the form field
  170
+	 *
  171
+	 * @var    mixed
  172
+	 * @since  11.1
  173
+	 */
  174
+	protected $labelClass;
  175
+
  176
+	/**
169 177
 	 * The count value for generated name field
170 178
 	 *
171 179
 	 * @var    integer
@@ -236,6 +244,7 @@ public function __get($name)
236 244
 			case 'type':
237 245
 			case 'validate':
238 246
 			case 'value':
  247
+			case 'labelClass':
239 248
 			case 'fieldname':
240 249
 			case 'group':
241 250
 				return $this->$name;
@@ -371,6 +380,9 @@ public function setup(SimpleXMLElement $element, $value, $group = null)
371 380
 		// Set the field default value.
372 381
 		$this->value = $value;
373 382
 
  383
+		// Set the CSS class of field label
  384
+		$this->labelClass = (string) $element['labelclass'];
  385
+
374 386
 		return true;
375 387
 	}
376 388
 
@@ -483,6 +495,7 @@ protected function getLabel()
483 495
 		// Build the class for the label.
484 496
 		$class = !empty($this->description) ? 'hasTip' : '';
485 497
 		$class = $this->required == true ? $class . ' required' : $class;
  498
+		$class = !empty($this->labelClass) ? $class . ' ' . $this->labelClass : $class;
486 499
 
487 500
 		// Add the opening label tag and main attributes attributes.
488 501
 		$label .= '<label id="' . $this->id . '-lbl" for="' . $this->id . '" class="' . $class . '"';
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.