Skip to content

Commit aa322d8

Browse files
author
Florian Kissling
committed
Another dirty one …:
* add class "control-label" where missing * add JS to on "select2-open" check if the parent elements has a class "has-*" (danger, warning, success) and copy this class to #select2-drop to inherit Bootstrap 3's validation state appearance for Select2 * lots of (sloppy) fixes regarding line-height and such, some still slightly off, but getting there
1 parent fdd72a8 commit aa322d8

File tree

11 files changed

+452
-184
lines changed

11 files changed

+452
-184
lines changed

_jekyll/_layouts/default.html

Lines changed: 43 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</div>
2626

2727
<div class="page-header">
28-
<h3>Input Groups <small><a href="http://getbootstrap.com/components/#input-groups"#></a> http://getbootstrap.com/components/#input-groups</small></h3>
28+
<h3>Input Groups <small><a href="http://getbootstrap.com/components/#input-groups" data-toggle="tooltip" data-placement="right" title="http://getbootstrap.com/components/#input-groups">#</a></small></h3>
2929
</div>
3030

3131
<div class="form-group">
@@ -121,29 +121,29 @@ <h3>Input Groups <small><a href="http://getbootstrap.com/components/#input-group
121121
<div class="container">
122122

123123
<div class="page-header">
124-
<h3>Control sizing <small><a href="http://getbootstrap.com/css/#forms-control-sizes">#</a> http://getbootstrap.com/css/#forms-control-sizes</small></h3>
124+
<h3>Control sizing <small><a href="http://getbootstrap.com/css/#forms-control-sizes" data-toggle="tooltip" data-placement="right" title="http://getbootstrap.com/css/#forms-control-sizes">#</a></small></h3>
125125
</div>
126126

127127
<div class="row">
128128
<div class="col-md-4">
129-
<label for="select2-multiple-input-sm">col-md-4</label>
129+
<label for="select2-multiple-input-sm" class="control-label">col-md-4</label>
130130
<select id="select2-multiple-input-sm" class="form-control input-sm select2-multiple" multiple>
131131
{% include select2-select.html %}
132132
</select>
133133
</div>
134134
<div class="col-md-3">
135-
<label for="select2-multiple-input-sm">col-md-3</label>
136-
<select id="select2-multiple-input-sm" class="form-control input-sm select2">
135+
<label for="select2-multiple-input-sm" class="control-label">col-md-3</label>
136+
<select id="select2-multiple-input-sm" class="form-control input-sm select2-multiple">
137137
{% include select2-select.html %}
138138
</select>
139139
</div>
140140
<div class="col-md-2">
141-
<label for="bootstrap-input-sm">Bootstrap input</label>
141+
<label for="bootstrap-input-sm" class="control-label">Bootstrap input</label>
142142
<input id="bootstrap-input-sm" class="form-control input-sm" placeholder=".input-sm">
143143
</div>
144144
<div class="col-md-3">
145-
<div class="form-group">
146-
<label for="select2-single-input-group-sm">col-md-3</label>
145+
<div class="form-group has-success">
146+
<label for="select2-single-input-group-sm" class="control-label">col-md-3</label>
147147
<div class="input-group input-group-sm select2-bootstrap-prepend">
148148
<span class="input-group-addon">
149149
<input type="radio">
@@ -158,14 +158,14 @@ <h3>Control sizing <small><a href="http://getbootstrap.com/css/#forms-control-si
158158
</div>
159159

160160
<div class="row">
161-
<div class="col-md-4">
162-
<label for="select2-multiple">col-md-4</label>
161+
<div class="col-md-4 has-warning">
162+
<label for="select2-multiple" class="control-label">col-md-4</label>
163163
<select id="select2-multiple" class="form-control select2-multiple" multiple>
164164
{% include select2-select.html %}
165165
</select>
166166
</div>
167167
<div class="col-md-3">
168-
<label for="span_small">col-md-3</label>
168+
<label for="span_small" class="control-label">col-md-3</label>
169169
<select id="span_small" class="form-control select2">
170170
{% include select2-select.html %}
171171
</select>
@@ -176,12 +176,12 @@ <h3>Control sizing <small><a href="http://getbootstrap.com/css/#forms-control-si
176176
</div>
177177
<div class="col-md-3">
178178
<div class="form-group">
179-
<label for="span_large">col-md-3</label>
179+
<label for="span_large" class="control-label">col-md-3</label>
180180
<div class="input-group select2-bootstrap-prepend">
181181
<span class="input-group-addon">
182182
<input type="checkbox">
183183
</span>
184-
<select id="span_large" class="form-control select2" multiple>
184+
<select id="span_large" class="form-control select2-multiple" multiple>
185185
<option></option>
186186
{% include select2-select.html %}
187187
</select>
@@ -192,30 +192,29 @@ <h3>Control sizing <small><a href="http://getbootstrap.com/css/#forms-control-si
192192

193193
<div class="row">
194194
<div class="col-md-4">
195-
<label for="select2-multiple-input-lg">col-md-4</label>
195+
<label for="select2-multiple-input-lg" class="control-label">col-md-4</label>
196196
<select id="select2-multiple-input-lg" class="form-control input-lg select2-multiple" multiple>
197197
{% include select2-select.html %}
198198
</select>
199199
</div>
200200
<div class="col-md-3">
201-
<label for="span-small">col-md-5</label>
201+
<label for="span-small" class="control-label">col-md-5</label>
202202
<select id="span-small" class="form-control input-lg select2-multiple">
203203
{% include select2-select.html %}
204204
</select>
205205
</div>
206206
<div class="col-md-2">
207-
<label for="bootstrap-input-lg">Bootstrap input</label>
207+
<label for="bootstrap-input-lg" class="control-label">Bootstrap input</label>
208208
<input id="bootstrap-input-lg" class="form-control input-lg" placeholder=".input-lg">
209209
</div>
210210
<div class="col-md-3">
211-
<div class="form-group">
212-
<label for="select2-multiple-input-group-lg">col-md-3</label>
211+
<div class="form-group has-error">
212+
<label for="select2-multiple-input-group-lg" class="control-label">col-md-3</label>
213213
<div class="input-group input-group-lg select2-bootstrap-prepend">
214214
<span class="input-group-addon">
215215
<input type="checkbox">
216216
</span>
217217
<select id="select2-multiple-input-group-lg" class="form-control select2">
218-
<option></option>
219218
{% include select2-select.html %}
220219
</select>
221220
</div>
@@ -224,7 +223,7 @@ <h3>Control sizing <small><a href="http://getbootstrap.com/css/#forms-control-si
224223
</div>
225224

226225
<div class="page-header">
227-
<h3>Button Addons <small><a href="http://getbootstrap.com/components/#input-groups-buttons">#</a> http://getbootstrap.com/components/#input-groups-buttons</small></h3>
226+
<h3>Button Addons <small><a href="http://getbootstrap.com/components/#input-groups-buttons" data-toggle="tooltip" data-placement="right" title="http://getbootstrap.com/components/#input-groups-buttons">#</a></small></h3>
228227
</div>
229228

230229
<div class="row">
@@ -245,8 +244,8 @@ <h3>Button Addons <small><a href="http://getbootstrap.com/components/#input-grou
245244
</div>
246245
</div>
247246
<div class="col-md-5">
248-
<label for="span_medium">col-md-5</label>
249-
<select id="span_medium" class="form-control select2" multiple>
247+
<label for="span_medium" class="control-label">col-md-5</label>
248+
<select id="span_medium" class="form-control select2-multiple" multiple>
250249
{% include select2-select.html %}
251250
</select>
252251
<span class="help-block"><code>span.help-block</code> A block of help text that breaks onto a new line and may extend beyond one line.</span>
@@ -256,19 +255,38 @@ <h3>Button Addons <small><a href="http://getbootstrap.com/components/#input-grou
256255

257256
{% include footer.html %}
258257

259-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
258+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
260259
<script src="http://ivaynberg.github.io/select2/select2-{{ page.version }}/select2.js"></script>
261260
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0-rc2/js/bootstrap.min.js"></script>
262261
<script>
262+
263263
$('.select2').select2({ placeholder: '' });
264264
$('.select2-multiple').select2({ placeholder: "Select a State", closeOnSelect: false });
265265
$('.select2-allow-clear').select2({ allowClear: true, placeholder: "Select a State" });
266-
$('.select2-remote').select2({ placeholder: 'Remote Data', data: [{id:'A', text:'A'}, {id:'B', text:'B'}, {id:'C', text:'C'} ] });
266+
$('.select2-remote').select2({ placeholder: 'Remote Data', data:
267+
[
268+
{ id:'A', text:'A' },
269+
{ id:'B', text:'B' },
270+
{ id:'C', text:'C' }
271+
]
272+
});
273+
274+
$(".select2, .select2-multiple, .select2-allow-clear, .select2-remote").on("select2-open", function() {
275+
if ( $(this).parents('[class*="has-"]').length ) {
276+
var classNames = $(this).parents('[class*="has-"]')[0].className.split(/\s+/);
277+
for (var i=0; i<classNames.length; ++i) {
278+
if ( classNames[i].match("has-") ) {
279+
$('#select2-drop').addClass( classNames[i] );
280+
}
281+
}
282+
}
283+
284+
});
267285

268286
$('button[data-select2-open]').click(function(){
269287
$('#' + $(this).data('select2-open')).select2('open');
270288
});
271-
</script>
272289

290+
</script>
273291
</body>
274292
</html>

_jekyll/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ <h2>Demonstrations</h2>
5353

5454
{% include footer.html %}
5555

56-
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
56+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
5757
<script src="http://ivaynberg.github.io/select2/select2-3.4.2/select2.js"></script>
5858
<script>
5959
$('.select2').select2({ placeholder: "Select a State", maximumSelectionSize: 6 });

_jekyll/select2-bootstrap.css

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
background: none;
3030
background-color: white;
3131
filter: none;
32+
padding: 0;
3233
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
3334
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
3435
}
@@ -40,7 +41,7 @@
4041
.select2-container-multi .select2-choices,
4142
.select2-container .select2-arrow {
4243
min-height: 34px;
43-
line-height: 35px;
44+
line-height: 1.42857;
4445
}
4546

4647
/**
@@ -52,7 +53,7 @@
5253
.input-group-sm .select2-container .select2-choice,
5354
.input-group-sm .select2-container-multi .select2-choices {
5455
min-height: 30px;
55-
line-height: 31px;
56+
line-height: 1.5;
5657
border-radius: 3px;
5758
}
5859

@@ -61,7 +62,7 @@
6162
.input-group-lg .select2-container .select2-choice,
6263
.input-group-lg .select2-container-multi .select2-choices {
6364
min-height: 45px;
64-
line-height: 46px;
65+
line-height: 1.33;
6566
border-radius: 6px;
6667
}
6768

@@ -131,19 +132,70 @@
131132
}
132133

133134
/**
134-
* Error styles from the original select2-bootstrap-css targeted at Bootstrap 2.
135-
* @todo: Implement test/demo and fix styles.
135+
* Address Bootstrap's validation states and change Select2's border colors and focus states.
136136
*/
137-
.form-group.error [class^="select2-choice"] {
137+
.has-warning .select2-choice,
138+
.has-warning .select2-choices {
139+
border-color: #c09853;
140+
}
141+
.has-warning .select2-container-active .select2-choice,
142+
.has-warning .select2-container-multi.select2-container-active .select2-choices {
143+
border-color: #a47e3c;
144+
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #dbc59e;
145+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #dbc59e;
146+
}
147+
.has-warning.select2-drop-active {
148+
border-color: #a47e3c !important;
149+
}
150+
151+
.has-error .select2-choice,
152+
.has-error .select2-choices {
138153
border-color: #b94a48;
139154
}
155+
.has-error .select2-container-active .select2-choice,
156+
.has-error .select2-container-multi.select2-container-active .select2-choices {
157+
border-color: #953b39;
158+
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #d59392;
159+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #d59392;
160+
}
161+
.has-error.select2-drop-active {
162+
border-color: #953b39 !important;
163+
}
164+
165+
.has-success .select2-choice,
166+
.has-success .select2-choices {
167+
border-color: #468847;
168+
}
169+
.has-success .select2-container-active .select2-choice,
170+
.has-success .select2-container-multi.select2-container-active .select2-choices {
171+
border-color: #356635;
172+
-webkit-box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #7aba7b;
173+
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075), 0 0 6px #7aba7b;
174+
}
175+
.has-success.select2-drop-active {
176+
border-color: #356635 !important;
177+
}
140178

141179
/**
142-
* .select2-search-field for multi-select Select2 widgets.
180+
* Adjust height and line-height for .select2-search-field amd multi-select Select2 widgets.
143181
*/
144-
.select2-container-multi .select2-choices .select2-search-field {
145-
height: 32px;
146-
line-height: 20px;
182+
.select2-chosen,
183+
.select2-container .select2-choices .select2-search-field input {
184+
padding: 6px 12px;
185+
}
186+
187+
.input-sm .select2-chosen,
188+
.input-group-sm .select2-chosen,
189+
.input-sm .select2-choices .select2-search-field input,
190+
.input-group-sm .select2-choices .select2-search-field input {
191+
padding: 5px 10px;
192+
}
193+
194+
.input-lg .select2-chosen,
195+
.input-group-lg .select2-chosen,
196+
.input-lg .select2-choices .select2-search-field input,
197+
.input-group-lg .select2-choices .select2-search-field input {
198+
padding: 10px 16px;
147199
}
148200

149201
/**
@@ -164,10 +216,6 @@
164216
border-color: #66afe9;
165217
}
166218

167-
[class^="input-"] .select2-container {
168-
font-size: 14px;
169-
}
170-
171219
/**
172220
* Select2 widgets in Bootstrap Input Groups
173221
*

0 commit comments

Comments
 (0)