Skip to content
This repository was archived by the owner on Aug 10, 2023. It is now read-only.

Commit 909b5fa

Browse files
committed
Integrate with bootstrap-select so that select fields look more in line with Bootstrap.
1 parent 15e110c commit 909b5fa

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ Integrating Bootstrap-looking form controls with Simple Form.
44

55
## Installation
66

7-
1. Add to your application's Gemfile: `gem 'simple_form-bootstrap'`
7+
1. Add to your application's Gemfile: `gem 'simple_form-bootstrap'`. The following types of
8+
input controls are supported, so long they are properly installed in your application. Ensure
9+
that the control is included in your `application.js` _before_ the Simple Form-Bootstrap
10+
JavaScript.
811

912
a. If you want to use Date/Time pickers, install the `bootstrap3-datetimepicker-rails` gem.
10-
Ensure that the picker is initialised in the JavaScript _before_ the Simple Form-Bootstrap
11-
JavaScript.
13+
b. If you want to use the nicely styled Bootstrap Select picker, install the
14+
`bootstrap-select-rails` gem.
1215

1316
2. Add to your application's javascript: `//= require simple_form-bootstrap`
1417
3. Create a new initializer:

app/assets/javascripts/simple_form-bootstrap.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@
66
// Enable our date/time pickers
77
var datePickers = $('input.bootstrap-datepicker', node);
88
datePickers.datetimepicker();
9+
10+
// Enable our styled Bootstrap select controls, except Twitter Typeahead controls.
11+
var selects = $('select.form-control:not(.typeahead)', node);
12+
selects.selectpicker();
913
}
1014

1115
$(document).on('ready', function(e) {
1216
initializeComponents(document);
13-
})
17+
});
1418
$(document).on('DOMNodeInserted', function(e) {
1519
initializeComponents(e.target);
1620
});
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Hijacks the default Bootstrap date-time picker to always format dates in the specified format
2+
// through the use of a hidden field.
3+
(function($) {
4+
'use strict';
5+
if ($.fn.selectpicker) {
6+
return;
7+
}
8+
9+
$.fn.selectpicker = function(arg) {
10+
return methods.initialise.call(this, arg);
11+
};
12+
}(jQuery));

0 commit comments

Comments
 (0)