From 2c62387a06e8cd0a65925457dd1da6e03f5c9d3c Mon Sep 17 00:00:00 2001 From: Uncle Cheese Date: Wed, 21 Oct 2015 11:47:05 +1300 Subject: [PATCH] BUGFIX: Do not add form-control to wrapping holder div, only field itself --- code/BootstrapFieldList.php | 38 ++++++++++++++++++++++--------------- code/BootstrapFormField.php | 17 +++++++++++++++++ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/code/BootstrapFieldList.php b/code/BootstrapFieldList.php index 13e96c4..be1b3cc 100644 --- a/code/BootstrapFieldList.php +++ b/code/BootstrapFieldList.php @@ -1,27 +1,32 @@ get('BootstrapForm','inline_fields'); - + /** + * Transforms all fields in the FieldList to use Bootstrap templates + * @return FieldList + */ + public function bootstrapify() { foreach($this->owner as $f) { - if(isset($this->ignores[$f->getName()])) continue; - if($f instanceof CompositeField) { - $f->getChildren()->bootstrapify(); - continue; + // If we have a Tabset, bootstrapify all Tabs + if($f instanceof TabSet) { + $f->Tabs()->bootstrapify(); } - if(!in_array($f->class, $inline_fields )) { - $f->addExtraClass('form-control'); + // If we have a Tab, bootstrapify all its Fields + if($f instanceof Tab) { + $f->Fields()->bootstrapify(); } $template = "Bootstrap{$f->class}_holder"; @@ -49,14 +54,17 @@ public function bootstrapify() { } return $this->owner; - } - - + /** + * Adds this field as ignored. Should not take on boostrap transformation + * + * @param string $field The name of the form field + * @return FieldList + */ public function bootstrapIgnore($field) { $this->ignores[$field] = true; return $this->owner; } -} +} \ No newline at end of file diff --git a/code/BootstrapFormField.php b/code/BootstrapFormField.php index 502ed69..7371665 100755 --- a/code/BootstrapFormField.php +++ b/code/BootstrapFormField.php @@ -178,5 +178,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 + */ + public function onBeforeRender (FormField $field) { + $inline_fields = Config::inst()->get('BootstrapForm','inline_fields'); + + if(!in_array($field->class, $inline_fields )) { + $field->addExtraClass('form-control'); + } + } + } \ No newline at end of file