Skip to content

Commit

Permalink
template update
Browse files Browse the repository at this point in the history
  • Loading branch information
Uncle Cheese committed Dec 22, 2014
0 parents commit 523237f
Show file tree
Hide file tree
Showing 289 changed files with 47,471 additions and 0 deletions.
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
silverstripe-bootstrap-forms
============================

Allows the creation of forms compatible with the Twitter Bootstrap CSS framework in SilverStripe 3.

## Basic Usage
Just use the "BootstrapForm" subclass instead of Form.
```php
<?php

$form = BootstrapForm::create(
$this,
"MyBootstrapForm",
FieldList::create(
TextField::create("Name")
->addHelpText('Enter some text above')
),
FieldList::create(
FormAction::create("doStuff","Click this!")
->setStyle("success")
)
);
```

### Bonus form fields
* SimpleHtmlEditorField
* ChosenDropdownField
* Textarea with maxlength

### The "Kitchen Sink" example
The following example showcases all of the options available on BootstrapForm and the BootstrapFormField extensions.

```php
<?php
public function FancyForm() {
return BootstrapForm::create(
$this,
"FancyForm",
FieldList::create(
TextField::create("ATextField","A text field with prepended and appended text")
->prependText("$")
->appendText(".00"),
CheckboxSetField::create("InlineCheckboxes","Inline Checkboxes")
->setSource(DataList::create("SiteTree"))
->setInline(true),
CheckboxSetField::create("Checkboxes","Checkboxes")
->setSource(DataList::create("SiteTree"))
->addHelpText("Check some of these."),
OptionsetField::create("InlineRadios","Inline Radios")
->setSource(DataList::create("SiteTree")->map('ID','Title'))
->setInline(true),

OptionsetField::create("Radios","Radios")
->setSource(DataList::create("SiteTree")->map('ID','Title'))
->addHelpText("Check one of these."),

DropdownField::create("Dropdown","Dropdown")
->setSource(DataList::create("SiteTree")->map('ID','Title'))
->addInlineHelpText("<-- look at that!"),
TextareaField::create("Textarea","Textarea"),
TextField::create("BigText","Massive text field")
->setSize("xxlarge"),
TextField::create("SmallText","Tiny text field")
->setSize("mini"),
SimpleHtmlEditorField::create("HTML", "HTML Editor")
->setButtons("bold,italic"),
ChosenDropdownField::create("FancyDropdown", "Fancy dropdown")
->setSource(SiteTree::get()->map()),
TextareaField::create("MaxLengthTextarea","Textarea with a maxlength")
->setAttribute('maxlength',150)
),
FieldList::create(
FormAction::create("yes","YES!")
->setStyle("success"),
FormAction::create("no","NO!")
->setStyle("danger"),
FormAction::create("maybe","Maybe...")
->setStyle("info"),
FormAction::create("sure","Sure!")
->setStyle("primary"),
FormAction::create("uhoh","Uh-oh")
->setStyle("warning")
)
)
->addWell()
->setLayout("horizontal");
}
}
```
3 changes: 3 additions & 0 deletions _config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

define('BOOTSTRAP_FORMS_DIR',basename(dirname(__FILE__)));
34 changes: 34 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: BootstrapForm
---
BootstrapForm:
bootstrap_included: false
jquery_included: false
bootstrap_form_included: false
inline_fields:
- CheckboxField
- FormAction
FormField:
extensions:
- BootstrapFormField
TextField:
extensions:
- BootstrapTextField
OptionsetField:
extensions:
- BootstrapOptionsetField
FormAction:
extensions:
- BootstrapFormAction
TextareaField:
extensions:
- BootstrapTextField
FieldList:
extensions:
- BootstrapFieldList
---
only:
moduleexists: userforms
---
UserDefinedForm_Controller:
extensions:
- BootstrapUserForm
51 changes: 51 additions & 0 deletions code/BootstrapButtonGroupField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php


class BootstrapButtonGroupField extends FormField
{

protected $optionsList;

public function __construct($name, $title = null, $options = array (), $value = null)
{
parent::__construct($name, $title, $value);
$this->optionsList = $options;

return $this;
}


public function setOptions($opts)
{
$this->optionsList = $opts;

return $this;
}



public function getOptions()
{
$options = ArrayList::create();
foreach($this->optionsList as $val => $label) {
$options->push(ArrayData::create(array(
'Label' => $label,
'Value' => $val,
'Selected' => $this->Value() == $val
)));
}

return $options;
}



public function Field($attributes = array ())
{
Requirements::javascript(BOOTSTRAP_FORMS_DIR."/javascript/bootstrap_forms.js");
return $this->renderWith('BootstrapButtonGroupField');
}



}
58 changes: 58 additions & 0 deletions code/BootstrapFieldList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php


class BootstrapFieldList extends Extension {

protected $ignores = array ();


public function bootstrapify() {
foreach($this->owner as $f) {

if(isset($this->ignores[$f->getName()])) continue;

// If we have a Tabset, bootstrapify all Tabs
if($f instanceof TabSet) {
$f->Tabs()->bootstrapify();
}

// If we have a Tab, bootstrapify all its Fields
if($f instanceof Tab) {
$f->Fields()->bootstrapify();
}

$template = "Bootstrap{$f->class}_holder";
if(SSViewer::hasTemplate($template)) {
$f->setFieldHolderTemplate($template);
}
else {
$f->setFieldHolderTemplate("BootstrapFieldHolder");
}

foreach(array_reverse(ClassInfo::ancestry($f)) as $className) {
$bootstrapCandidate = "Bootstrap{$className}";
$nativeCandidate = $className;
if(SSViewer::hasTemplate($bootstrapCandidate)) {
$f->setTemplate($bootstrapCandidate);
break;
}
elseif(SSViewer::hasTemplate($nativeCandidate)) {
$f->setTemplate($nativeCandidate);
break;
}


}
}

return $this->owner;

}


public function bootstrapIgnore($field) {
$this->ignores[$field] = true;

return $this->owner;
}
}
Loading

0 comments on commit 523237f

Please sign in to comment.