From 562c6f1a108384e655262510f43feb7a62dac265 Mon Sep 17 00:00:00 2001 From: Phill Price Date: Sat, 15 Nov 2014 19:48:27 +0000 Subject: [PATCH] Enable adding classes to input and label directly --- code/BootstrapFormField.php | 72 +++++++++++++++++++--- templates/BootstrapCheckboxField_holder.ss | 6 +- 2 files changed, 66 insertions(+), 12 deletions(-) diff --git a/code/BootstrapFormField.php b/code/BootstrapFormField.php index c90768b..1eea02f 100755 --- a/code/BootstrapFormField.php +++ b/code/BootstrapFormField.php @@ -20,10 +20,16 @@ class BootstrapFormField extends DataExtension { "form-group" ); + protected $labelClasses = array( + ); + + protected $inputClasses = array( + ); + /** * Adds a HTML5 placeholder attribute to the form field - * + * * @param $text the placeholder text to add * @return BootstrapFormField */ @@ -31,7 +37,7 @@ public function addPlaceholder($text) { return $this->owner->setAttribute("placeholder",$text); } - + /** * Adds a block of help text to the form field. (HTML safe). * By default, this text appears below a field and its label. @@ -89,13 +95,61 @@ public function HolderAttributes() { } /** - * Allows adding custom classes to the holder - * + * Allows adding custom classes to the input + * + * @param string $class the class + * + * @return BootstrapFormField + */ + public function addInputClass($class) { + $this->inputClasses[] = $class; + return $this->owner; + } + + /** + * returns the input classes to be used in templates + * also triggers checking for error messages + * + * @return string of classes + */ + public function InputClasses() { + $this->loadErrorMessage(); + + return implode(" ",$this->inputClasses); + } + + /** + * Allows adding custom classes to the label + * + * @param string $class the class + * + * @return BootstrapFormField + */ + public function addLabelClass($class) { + $this->labelClasses[] = $class; + return $this->owner; + } + + /** + * returns the label classes to be used in templates + * also triggers checking for error messages + * + * @return string of classes + */ + public function LabelClasses() { + $this->loadErrorMessage(); + + return implode(" ",$this->labelClasses); + } + + /** + * Allows adding custom classes to the holder + * * @param string $class the class - * + * * @return BootstrapFormField */ - public function addHolderClass($class) { + public function addHolderClass($class) { $this->holderClasses[] = $class; return $this->owner; } @@ -103,7 +157,7 @@ public function addHolderClass($class) { /** * returns the holder classes to be used in templates * also triggers checking for error messages - * + * * @return string of classes */ public function HolderClasses() { @@ -127,7 +181,7 @@ public function onBeforeRender() { /** * checks for error messages in owner form field * adds error class to holder and loads error message as helptext - * + * * @todo allow setting error message as inline */ private function loadErrorMessage() { @@ -136,5 +190,5 @@ private function loadErrorMessage() { $this->addHelpText($this->owner->message); } } - + } \ No newline at end of file diff --git a/templates/BootstrapCheckboxField_holder.ss b/templates/BootstrapCheckboxField_holder.ss index 6cc1718..06091b9 100755 --- a/templates/BootstrapCheckboxField_holder.ss +++ b/templates/BootstrapCheckboxField_holder.ss @@ -1,13 +1,13 @@
-