Skip to content

Commit

Permalink
Merge pull request #33 from phillprice/feature/label-holder-classes
Browse files Browse the repository at this point in the history
Enable adding classes to input and label directly (also needs work in display-logic module)
  • Loading branch information
unclecheese committed Nov 21, 2014
2 parents 394c64e + 562c6f1 commit 5706d26
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 12 deletions.
72 changes: 63 additions & 9 deletions code/BootstrapFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,24 @@ 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
*/
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.
Expand Down Expand Up @@ -89,21 +95,69 @@ 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;
}

/**
* returns the holder classes to be used in templates
* also triggers checking for error messages
*
*
* @return string of classes
*/
public function HolderClasses() {
Expand All @@ -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() {
Expand All @@ -136,5 +190,5 @@ private function loadErrorMessage() {
$this->addHelpText($this->owner->message);
}
}

}
6 changes: 3 additions & 3 deletions templates/BootstrapCheckboxField_holder.ss
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<div id="$Name" class="checkbox $HolderClasses" $HolderAttributes>
<label>
<input $AttributesHTML>
<label class="$labelClasses">
$Title
<input $AttributesHTML class="$inputClasses">
</label>
<% if $HelpText %>
<p class="help-block">$HelpText</p>
<% end_if %>
<% if $InlineHelpText %>
<span class="help-inline">$InlineHelpText</span>
<% end_if %>
<% end_if %>
</div>

0 comments on commit 5706d26

Please sign in to comment.