-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from colinedmz/feature-dropdownfield
Feature DropdownField
- Loading branch information
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
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,39 @@ | ||
<?php | ||
|
||
class BootstrapDropdownField extends DropdownField { | ||
protected $optionsList; | ||
|
||
public function __construct($name, $title = NULL, $options = array(), $value = NULL) { | ||
parent::__construct($name, $title, $value); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
$this->optionsList = $options; | ||
|
||
return $this; | ||
} | ||
|
||
public function setOptions($opts) { | ||
$this->optionsList = $opts; | ||
|
||
return $this; | ||
} | ||
|
||
public function getOptions() { | ||
$options = ArrayList::create(); | ||
$selectedValue = $this->Value(); | ||
foreach ($this->optionsList as $val => $label) { | ||
$isSelected = $selectedValue == (string) $val; | ||
$options->push(ArrayData::create(array( | ||
'Label' => $label, | ||
'Value' => $val, | ||
'Selected' => $isSelected | ||
))); | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
public function Field($attributes = array()) { | ||
Requirements::javascript(BOOTSTRAP_FORMS_DIR . "/javascript/bootstrap_forms.js"); | ||
|
||
return $this->renderWith('BootstrapDropdownField'); | ||
} | ||
} |
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
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,24 @@ | ||
<span class="btn-group"> | ||
<select name="$Name" id="{$id}_select" class="dropdown-select"> | ||
<% loop $Options %> | ||
<option <% if $Selected %>selected="selected"<% end_if %> value="$Value">$Label</option> | ||
<% end_loop %> | ||
</select> | ||
<button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown"> | ||
<% loop $Options %> | ||
<% if $Selected %> | ||
<span id="{$Top.id}_label" data-default="$Top.Title" class="dropdown-label">$Label</span> | ||
<% end_if %> | ||
<% end_loop %> | ||
<span class="caret"></span> | ||
</button> | ||
<ul class="dropdown-menu" role="menu" aria-labelledby="{$id}_label"> | ||
<% loop $Options %> | ||
<li role="presentation"> | ||
<a data-value="$Value" rel="#$Top.id" role="menuitem" tabindex="-1" | ||
href="#">$Label | ||
</a> | ||
</li> | ||
<% end_loop %> | ||
</ul> | ||
</span> |
Missing
$options
#49