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.
Changed BootstrapDropdownField to avoid conflicts with with DropdownField and ChosenDropdownfield. BootstrapDropdownField: Changed to render with default Dropdownfield.ss template. Use bootstrap-select JS plugin by adding ExtraClass 'selectpicker'. Add option bootstrap_select_included to config.yml ChosenDropdownField Include/add chosen v1.6.2 library With bootstrap_included set to false: load silverstripe thirdparty jquery and /admin/thirdparty/chosen/chosen/chosen.jquery.js With bootstrap_included set to true: load chosen v1.6.2 (silverstripe bundled version /admin/thirdparty/chosen/chosen/chosen.jquery.js uses jQuery.browser() method which removed since jQuery 1.9 – but Bootstrap 3.3.6 and above requires jQuery 1.9.1+) caveats: BootstrapDropdownField can't be used with jquery_included set to false, as this will include the ss-bundled version which is too low. To use BootstrapDropdownField you will need to include jQuery 1.9.1+ (Bootstrap 3.3 and above requires 1.9.1+ anyway)
- Loading branch information
derralf
authored and
derralf
committed
Oct 17, 2016
1 parent
05e7829
commit 90111d9
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.