Skip to content

Commit 857d9f5

Browse files
authored
Merge pull request pallets-eco#1728 from flask-admin/fix-search-placeholder
Fix search placeholder
2 parents d627014 + 53787ac commit 857d9f5

File tree

8 files changed

+66
-15
lines changed

8 files changed

+66
-15
lines changed

doc/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Changelog
99
* SQLAlchemy
1010
* sort on multiple columns with `column_default_sort`
1111
* sort on related models in `column_sortable_list`
12+
* show searchable fields in search input's placeholder text
1213
* fix: inline model forms can now also be used for models with multiple primary keys
1314
* support for using mapped `column_property`
1415
* Upgrade Leaflet and Leaflet.draw plugins, used for geoalchemy integration

examples/sqla/app.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,16 @@ class PostAdmin(sqla.ModelView):
202202
column_labels = dict(title='Post Title') # Rename 'title' column in list view
203203
column_searchable_list = [
204204
'title',
205-
User.first_name,
206-
User.last_name,
207205
'tags.name',
206+
'user.first_name',
207+
'user.last_name',
208208
]
209+
column_labels = {
210+
'title': 'Title',
211+
'tags.name': 'tags',
212+
'user.first_name': 'user\'s first name',
213+
'user.last_name': 'last name',
214+
}
209215
column_filters = [
210216
'user',
211217
'title',

flask_admin/contrib/sqla/view.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,10 @@ class MyModelView(BaseModelView):
590590
column_labels = dict(name='Name', last_name='Last Name')
591591
column_searchable_list = ('name', 'last_name')
592592
593-
placeholder is: "Search: Name, Last Name"
593+
placeholder is: "Name, Last Name"
594594
"""
595595
if not self.column_searchable_list:
596-
return 'Search'
596+
return None
597597

598598
placeholders = []
599599

@@ -605,7 +605,7 @@ class MyModelView(BaseModelView):
605605
placeholders.append(
606606
self.column_labels.get(searchable, searchable))
607607

608-
return 'Search: %s' % u', '.join(placeholders)
608+
return u', '.join(placeholders)
609609

610610
def scaffold_filters(self, name):
611611
"""

flask_admin/model/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,9 +1109,9 @@ def init_search(self):
11091109

11101110
def search_placeholder(self):
11111111
"""
1112-
Return search placeholder.
1112+
Return search placeholder text.
11131113
"""
1114-
return 'Search'
1114+
return None
11151115

11161116
# Filter helpers
11171117
def scaffold_filters(self, name):

flask_admin/static/admin/css/bootstrap2/admin.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,23 @@ table.filters tr td {
143143
.editable-input .select2-container {
144144
min-width: 220px;
145145
}
146+
147+
[placeholder]{
148+
text-overflow:ellipsis;
149+
}
150+
151+
::-webkit-input-placeholder { /* Chrome/Opera/Safari */
152+
text-overflow:ellipsis;
153+
}
154+
155+
::-moz-placeholder { /* Firefox 19+ */
156+
text-overflow:ellipsis;
157+
}
158+
159+
:-ms-input-placeholder { /* IE 10+ */
160+
text-overflow:ellipsis;
161+
}
162+
163+
:-moz-placeholder { /* Firefox 18- */
164+
text-overflow:ellipsis;
165+
}

flask_admin/static/admin/css/bootstrap3/admin.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,23 @@ body.modal-open {
108108
{
109109
overflow-x: auto;
110110
}
111+
112+
[placeholder]{
113+
text-overflow:ellipsis;
114+
}
115+
116+
::-webkit-input-placeholder { /* Chrome/Opera/Safari */
117+
text-overflow:ellipsis;
118+
}
119+
120+
::-moz-placeholder { /* Firefox 19+ */
121+
text-overflow:ellipsis;
122+
}
123+
124+
:-ms-input-placeholder { /* IE 10+ */
125+
text-overflow:ellipsis;
126+
}
127+
128+
:-moz-placeholder { /* Firefox 18- */
129+
text-overflow:ellipsis;
130+
}

flask_admin/templates/bootstrap2/admin/model/layout.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<div class="clearfix"></div>
5959
{% endmacro %}
6060

61-
{% macro search_form(input_class="span2") %}
61+
{% macro search_form(input_class=None) %}
6262
<form method="GET" action="{{ return_url }}" class="search-form">
6363
{% for flt_name, flt_value in filter_args.items() %}
6464
<input type="hidden" name="{{ flt_name }}" value="{{ flt_value }}">
@@ -72,17 +72,17 @@
7272
{% if sort_desc %}
7373
<input type="hidden" name="desc" value="{{ sort_desc }}">
7474
{% endif %}
75+
{%- set full_search_placeholder = _gettext('Search') %}
76+
{%- if search_placeholder %}{% set full_search_placeholder = [full_search_placeholder, search_placeholder] | join(": ") %}{% endif %}
7577
{% if search %}
7678
<div class="input-append">
77-
<input type="text" name="search" value="{{ search }}" class="{{ input_class }}" placeholder="{{ _gettext('%(placeholder)s', placeholder=search_placeholder) }}">
79+
<input type="search" name="search" class="input-xlarge{% if input_class %} {{ input_class }}{% endif %}" value="{{ search }}" placeholder="{{ full_search_placeholder }}">
7880
<a href="{{ clear_search_url }}" class="clear add-on">
7981
<i class="fa fa-times icon-remove"></i>
8082
</a>
8183
</div>
8284
{% else %}
83-
<div>
84-
<input type="text" name="search" value="" class="{{ input_class }}" placeholder="{{ _gettext('%(placeholder)s', placeholder=search_placeholder) }}">
85-
</div>
85+
<input type="search" name="search" class="input-xlarge{% if input_class %} {{ input_class }}{% endif %}" value="" placeholder="{{ full_search_placeholder }}">
8686
{% endif %}
8787
</form>
8888
{% endmacro %}

flask_admin/templates/bootstrap3/admin/model/layout.html

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<div class="clearfix"></div>
5959
{% endmacro %}
6060

61-
{% macro search_form(input_class="col-md-2") %}
61+
{% macro search_form(input_class=None) %}
6262
<form method="GET" action="{{ return_url }}" class="navbar-form navbar-left" role="search">
6363
{% for flt_name, flt_value in filter_args.items() %}
6464
<input type="hidden" name="{{ flt_name }}" value="{{ flt_value }}">
@@ -72,14 +72,18 @@
7272
{% if sort_desc %}
7373
<input type="hidden" name="desc" value="{{ sort_desc }}">
7474
{% endif %}
75+
{%- set full_search_placeholder = _gettext('Search') %}
76+
{%- set max_size = config.get('FLASK_ADMIN_SEARCH_SIZE_MAX', 100) %}
77+
{%- if search_placeholder %}{% set full_search_placeholder = [full_search_placeholder, search_placeholder] | join(": ") %}{% endif %}
78+
{%- set input_size = [[full_search_placeholder | length, 30] | max, max_size] | min %}
7579
{% if search %}
7680
<div class="input-group">
77-
<input type="text" name="search" value="{{ search }}" class="{{ input_class }} form-control" placeholder="{{ _gettext('%(placeholder)s', placeholder=search_placeholder) }}">
81+
<input type="search" name="search" value="{{ search }}" class="form-control{% if input_class %} {{ input_class }}{% endif %}" size="{{ input_size }}" placeholder="{{ full_search_placeholder }}">
7882
<a href="{{ clear_search_url }}" class="input-group-addon clear"><span class="fa fa-times glyphicon glyphicon-remove"></span></a>
7983
</div>
8084
{% else %}
8185
<div class="form-group">
82-
<input type="text" name="search" value="" class="{{ input_class }} form-control" placeholder="{{ _gettext('%(placeholder)s', placeholder=search_placeholder) }}">
86+
<input type="search" name="search" value="" class="form-control{% if input_class %} {{ input_class }}{% endif %}" size="{{ input_size }}" placeholder="{{ full_search_placeholder }}">
8387
</div>
8488
{% endif %}
8589
</form>

0 commit comments

Comments
 (0)