forked from unclecheese/silverstripe-bootstrap-forms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Uncle Cheese
committed
Dec 22, 2014
0 parents
commit 523237f
Showing
289 changed files
with
47,471 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
define('BOOTSTRAP_FORMS_DIR',basename(dirname(__FILE__))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.