File tree Expand file tree Collapse file tree 8 files changed +66
-15
lines changed Expand file tree Collapse file tree 8 files changed +66
-15
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ Changelog
9
9
* SQLAlchemy
10
10
* sort on multiple columns with `column_default_sort `
11
11
* sort on related models in `column_sortable_list `
12
+ * show searchable fields in search input's placeholder text
12
13
* fix: inline model forms can now also be used for models with multiple primary keys
13
14
* support for using mapped `column_property `
14
15
* Upgrade Leaflet and Leaflet.draw plugins, used for geoalchemy integration
Original file line number Diff line number Diff line change @@ -202,10 +202,16 @@ class PostAdmin(sqla.ModelView):
202
202
column_labels = dict (title = 'Post Title' ) # Rename 'title' column in list view
203
203
column_searchable_list = [
204
204
'title' ,
205
- User .first_name ,
206
- User .last_name ,
207
205
'tags.name' ,
206
+ 'user.first_name' ,
207
+ 'user.last_name' ,
208
208
]
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
+ }
209
215
column_filters = [
210
216
'user' ,
211
217
'title' ,
Original file line number Diff line number Diff line change @@ -590,10 +590,10 @@ class MyModelView(BaseModelView):
590
590
column_labels = dict(name='Name', last_name='Last Name')
591
591
column_searchable_list = ('name', 'last_name')
592
592
593
- placeholder is: "Search: Name, Last Name"
593
+ placeholder is: "Name, Last Name"
594
594
"""
595
595
if not self .column_searchable_list :
596
- return 'Search'
596
+ return None
597
597
598
598
placeholders = []
599
599
@@ -605,7 +605,7 @@ class MyModelView(BaseModelView):
605
605
placeholders .append (
606
606
self .column_labels .get (searchable , searchable ))
607
607
608
- return 'Search: %s' % u', ' .join (placeholders )
608
+ return u', ' .join (placeholders )
609
609
610
610
def scaffold_filters (self , name ):
611
611
"""
Original file line number Diff line number Diff line change @@ -1109,9 +1109,9 @@ def init_search(self):
1109
1109
1110
1110
def search_placeholder (self ):
1111
1111
"""
1112
- Return search placeholder.
1112
+ Return search placeholder text .
1113
1113
"""
1114
- return 'Search'
1114
+ return None
1115
1115
1116
1116
# Filter helpers
1117
1117
def scaffold_filters (self , name ):
Original file line number Diff line number Diff line change @@ -143,3 +143,23 @@ table.filters tr td {
143
143
.editable-input .select2-container {
144
144
min-width : 220px ;
145
145
}
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
+ }
Original file line number Diff line number Diff line change @@ -108,3 +108,23 @@ body.modal-open {
108
108
{
109
109
overflow-x : auto;
110
110
}
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
+ }
Original file line number Diff line number Diff line change 58
58
< div class ="clearfix "> </ div >
59
59
{% endmacro %}
60
60
61
- {% macro search_form(input_class="span2" ) %}
61
+ {% macro search_form(input_class=None ) %}
62
62
< form method ="GET " action ="{{ return_url }} " class ="search-form ">
63
63
{% for flt_name, flt_value in filter_args.items() %}
64
64
< input type ="hidden " name ="{{ flt_name }} " value ="{{ flt_value }} ">
72
72
{% if sort_desc %}
73
73
< input type ="hidden " name ="desc " value ="{{ sort_desc }} ">
74
74
{% endif %}
75
+ {%- set full_search_placeholder = _gettext('Search') %}
76
+ {%- if search_placeholder %}{% set full_search_placeholder = [full_search_placeholder, search_placeholder] | join(": ") %}{% endif %}
75
77
{% if search %}
76
78
< 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 }} ">
78
80
< a href ="{{ clear_search_url }} " class ="clear add-on ">
79
81
< i class ="fa fa-times icon-remove "> </ i >
80
82
</ a >
81
83
</ div >
82
84
{% 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 }} ">
86
86
{% endif %}
87
87
</ form >
88
88
{% endmacro %}
Original file line number Diff line number Diff line change 58
58
< div class ="clearfix "> </ div >
59
59
{% endmacro %}
60
60
61
- {% macro search_form(input_class="col-md-2" ) %}
61
+ {% macro search_form(input_class=None ) %}
62
62
< form method ="GET " action ="{{ return_url }} " class ="navbar-form navbar-left " role ="search ">
63
63
{% for flt_name, flt_value in filter_args.items() %}
64
64
< input type ="hidden " name ="{{ flt_name }} " value ="{{ flt_value }} ">
72
72
{% if sort_desc %}
73
73
< input type ="hidden " name ="desc " value ="{{ sort_desc }} ">
74
74
{% 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 %}
75
79
{% if search %}
76
80
< 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 }} ">
78
82
< a href ="{{ clear_search_url }} " class ="input-group-addon clear "> < span class ="fa fa-times glyphicon glyphicon-remove "> </ span > </ a >
79
83
</ div >
80
84
{% else %}
81
85
< 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 }} ">
83
87
</ div >
84
88
{% endif %}
85
89
</ form >
You can’t perform that action at this time.
0 commit comments