Skip to content

Commit

Permalink
Added support for Bootstrap 3
Browse files Browse the repository at this point in the history
  • Loading branch information
mi32dogs authored Nov 12, 2016
1 parent 969a7d6 commit 4eddea6
Showing 1 changed file with 79 additions and 9 deletions.
88 changes: 79 additions & 9 deletions code/BootstrapFormField.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ class BootstrapFormField extends DataExtension {
);


/**
* The label grid class for the bootstrap 3 horizontal form
* overrides form setting
*
* @var String
*/
protected $gridLabelClass = '';

/**
* The input grid class for the bootstrap 3 horizontal form
* overrides form setting
*
* @var String
*/
protected $gridInputClass = '';


/**
* Adds a HTML5 placeholder attribute to the form field
*
Expand Down Expand Up @@ -166,6 +183,59 @@ public function HolderClasses() {
return implode(" ",$this->holderClasses);
}


/**
* returns the bootstrap Layout to be used in templates
*
* @return string
*/
public function BootstrapLayout() {
return $this->owner->form->formLayout;
}

/**
* Allows setting custom Grid label class to override from grid label class
*
* @param string $class
*
* @return BootstrapFormField
*/
public function setGridLabelClass($class) {
$this->gridLabelClass = $class;
return $this->owner;
}

/**
* Allows setting custom Grid input class to override from grid label class
*
* @param string $class
*
* @return BootstrapFormField
*/
public function setGridInputClass($class) {
$this->gridInputClass = $class;
return $this->owner;
}

/**
* returns Grid label class to be used in templates
*
* @return integer
*/
public function GridLabelClass() {
return (trim($this->gridLabelClass)!='')?$this->gridLabelClass:$this->owner->form->gridLabelClass;
}

/**
* returns Grid input class to be used in templates
*
* @return integer
*/
public function GridInputClass() {
return (trim($this->gridInputClass)!='')?$this->gridInputClass:$this->owner->form->gridInputClass;
}


/**
* checks for error messages in owner form field
* adds error class to holder and loads error message as helptext
Expand All @@ -178,22 +248,22 @@ private function loadErrorMessage() {
$this->addHelpText($this->owner->message);
}
}

/**
* Adds the form-control class to *just* the formfield, not the holder.
* This seems a bit of a hack, but addExtraClass() affects both the holder
* and the field, so that's not a realistic option. We can't have form-control
* on the wrapping div.
*
* @param FormField $field
*
* @param FormField $field
*/
public function onBeforeRender (FormField $field) {
$inline_fields = Config::inst()->get('BootstrapForm','inline_fields');
public function onBeforeRender (FormField $field) {
$inline_fields = Config::inst()->get('BootstrapForm','inline_fields');

if(!in_array($field->class, $inline_fields )) {
$field->addExtraClass('form-control');
}
if(!in_array($field->class, $inline_fields )) {
$field->addExtraClass('form-control');
}
}


}
}

0 comments on commit 4eddea6

Please sign in to comment.