Skip to content

Commit

Permalink
feature #400 Dropdowns are now displayed with the Select2 library wid…
Browse files Browse the repository at this point in the history
…get (javiereguiluz)

This PR was squashed before being merged into the master branch (closes #400).

Discussion
----------

Dropdowns are now displayed with the Select2 library widget

This fixes #133.

This little PR integrates the excellent Select2 library to display long dropdowns in a sane way:

![select2](https://cloud.githubusercontent.com/assets/73419/8786683/ebab837c-2f2f-11e5-8f17-90df18077d5a.gif)

Commits
-------

f256320 Dropdowns are now displayed with the Select2 library widget
  • Loading branch information
javiereguiluz committed Jul 21, 2015
2 parents f4dd66e + f256320 commit 1f9bbc2
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Resources/public/javascript/select2.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions Resources/public/stylesheet/select2.min.css

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions Resources/views/css/admin.css.twig
Expand Up @@ -348,6 +348,30 @@ button.btn-danger {
margin-bottom: .5em;
}

/* Select2 widget
------------------------------------------------------------------------- */
.select2-container--bootstrap .select2-selection {
border: 1px solid {{ colors.gray_dark }};
}
.select2-container--bootstrap .select2-selection--single .select2-selection__rendered {
color: {{ colors.text }};
}
.select2-container--bootstrap .select2-results__option {
margin-bottom: 0;
}
.select2-container--bootstrap .select2-results__option[aria-selected=true] {
background-color: {{ colors.gray_light }};
font-weight: bold;
}
.select2-container--bootstrap .select2-results__option--highlighted[aria-selected] {
background-color: {{ brand_color }};
}
.select2-container--bootstrap .select2-search--dropdown .select2-search__field {
border: 1px solid {{ colors.gray_dark }};
margin: 5px 1%;
width: 96%;
}

/* Modal windows
------------------------------------------------------------------------- */
.modal-dialog .modal-content {
Expand Down
14 changes: 14 additions & 0 deletions Resources/views/default/edit.html.twig
Expand Up @@ -54,6 +54,11 @@
{% endblock delete_form %}
{% endblock %}

{% block head_stylesheets %}
<link rel="stylesheet" href="{{ asset('bundles/easyadmin/stylesheet/select2.min.css') }}">
{{ parent() }}
{% endblock %}

{% block body_javascript %}
{{ parent() }}

Expand All @@ -72,4 +77,13 @@
});
});
</script>

<script src="{{ asset('bundles/easyadmin/javascript/select2.min.js') }}"></script>
<script type="text/javascript">
$(function() {
$('#main form select').select2({
theme: 'bootstrap'
});
});
</script>
{% endblock %}
14 changes: 14 additions & 0 deletions Resources/views/default/new.html.twig
Expand Up @@ -19,6 +19,11 @@
{% endblock entity_form %}
{% endblock %}

{% block head_stylesheets %}
<link rel="stylesheet" href="{{ asset('bundles/easyadmin/stylesheet/select2.min.css') }}">
{{ parent() }}
{% endblock %}

{% block body_javascript %}
{{ parent() }}

Expand All @@ -28,4 +33,13 @@
$('#new-form').areYouSure({ 'message': 'You haven\'t saved the changes made on this form.' });
});
</script>

<script src="{{ asset('bundles/easyadmin/javascript/select2.min.js') }}"></script>
<script type="text/javascript">
$(function() {
$('#main form select').select2({
theme: 'bootstrap'
});
});
</script>
{% endblock %}
4 changes: 2 additions & 2 deletions Tests/Controller/DefaultBackendTest.php
Expand Up @@ -85,9 +85,9 @@ public function testAdminCssFile()
$this->client->request('GET', '/admin/_css/admin.css');

$this->assertEquals('text/css; charset=UTF-8', $this->client->getResponse()->headers->get('Content-Type'));
$this->assertEquals(19, substr_count($this->client->getResponse()->getContent(), '#E67E22'), 'The admin.css file uses the default brand color.');
$this->assertEquals(20, substr_count($this->client->getResponse()->getContent(), '#E67E22'), 'The admin.css file uses the default brand color.');
// #222222 color is only used by the "dark" color scheme, not the "light" one
$this->assertEquals(15, substr_count($this->client->getResponse()->getContent(), '#222222'), 'The admin.css file uses the dark color scheme.');
$this->assertEquals(16, substr_count($this->client->getResponse()->getContent(), '#222222'), 'The admin.css file uses the dark color scheme.');
}

public function testListViewMainMenu()
Expand Down

0 comments on commit 1f9bbc2

Please sign in to comment.