-
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 #51 from derralf/dropdown-bugfix
Fix dropdown fields
- Loading branch information
Showing
79 changed files
with
5,409 additions
and
71 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
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 |
---|---|---|
@@ -1,39 +1,28 @@ | ||
<?php | ||
|
||
/** | ||
* Defines a FormField that uses the bootstrap-select JS plugin for making | ||
* dropdown fields nice. | ||
* | ||
*/ | ||
class BootstrapDropdownField extends DropdownField { | ||
protected $optionsList; | ||
|
||
public function __construct($name, $title = NULL, $options = array(), $value = NULL) { | ||
parent::__construct($name, $title,$options, $value); | ||
$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 | ||
))); | ||
/** | ||
* Builds the form field, sets default attributes, and includes JS | ||
* | ||
* @param array $attributes The attributes to include on the formfield | ||
* @return SSViewer | ||
*/ | ||
public function FieldHolder($attributes = array ()) { | ||
if(!Config::inst()->get('BootstrapForm', 'bootstrap_select_included')) { | ||
$current_locale = (class_exists('Translatable')) ? Translatable::get_current_locale() : i18n::get_locale(); | ||
Requirements::javascript(BOOTSTRAP_FORMS_DIR."/javascript/bootstrap-select/js/bootstrap-select.min.js"); | ||
Requirements::javascript(BOOTSTRAP_FORMS_DIR."/javascript/bootstrap-select/js/i18n/defaults-{$current_locale}.js"); | ||
Requirements::css(BOOTSTRAP_FORMS_DIR."/javascript/bootstrap-select/css/bootstrap-select.min.css"); | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
public function Field($attributes = array()) { | ||
Requirements::javascript(BOOTSTRAP_FORMS_DIR . "/javascript/bootstrap_forms.js"); | ||
|
||
return $this->renderWith('BootstrapDropdownField'); | ||
$this->addExtraClass('selectpicker'); | ||
return parent::FieldHolder($attributes); | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.