Commit 3210839a authored by Legolas Bloom's avatar Legolas Bloom

new: support search placeholder

parent d4a8cef6
......@@ -555,6 +555,33 @@ class ModelView(BaseModelView):
return bool(self.column_searchable_list)
def search_placeholder(self):
"""
Return search placeholder.
For example, if set column_labels and column_searchable_list:
class MyModelView(BaseModelView):
column_labels = dict(name='Name', last_name='Last Name')
column_searchable_list = ('name', 'last_name')
placeholder is: "Search: Name, Last Name"
"""
if not self.column_searchable_list:
return 'Search'
placeholders = []
for searchable in self.column_searchable_list:
if isinstance(searchable, InstrumentedAttribute):
placeholders.append(
self.column_labels.get(searchable.key, searchable.key))
else:
placeholders.append(
self.column_labels.get(searchable, searchable))
return 'Search: %s' % u', '.join(placeholders)
def scaffold_filters(self, name):
"""
Return list of enabled filters
......
......@@ -1050,6 +1050,12 @@ class BaseModelView(BaseView, ActionsMixin):
"""
return False
def search_placeholder(self):
"""
Return search placeholder.
"""
return 'Search'
# Filter helpers
def scaffold_filters(self, name):
"""
......@@ -1880,6 +1886,7 @@ class BaseModelView(BaseView, ActionsMixin):
search_supported=self._search_supported,
clear_search_url=clear_search_url,
search=view_args.search,
search_placeholder=self.search_placeholder(),
# Filters
filters=self._filters,
......
......@@ -56,14 +56,14 @@
{% endif %}
{% if search %}
<div class="input-append">
<input type="text" name="search" value="{{ search }}" class="{{ input_class }}" placeholder="{{ _gettext('Search') }}">
<input type="text" name="search" value="{{ search }}" class="{{ input_class }}" placeholder="{{ _gettext('%(placeholder)s', placeholder=search_placeholder) }}">
<a href="{{ clear_search_url }}" class="clear add-on">
<i class="fa fa-times icon-remove"></i>
</a>
</div>
{% else %}
<div>
<input type="text" name="search" value="" class="{{ input_class }}" placeholder="{{ _gettext('Search') }}">
<input type="text" name="search" value="" class="{{ input_class }}" placeholder="{{ _gettext('%(placeholder)s', placeholder=search_placeholder) }}">
</div>
{% endif %}
</form>
......
......@@ -56,12 +56,12 @@
{% endif %}
{% if search %}
<div class="input-group">
<input type="text" name="search" value="{{ search }}" class="{{ input_class }} form-control" placeholder="{{ _gettext('Search') }}">
<input type="text" name="search" value="{{ search }}" class="{{ input_class }} form-control" placeholder="{{ _gettext('%(placeholder)s', placeholder=search_placeholder) }}">
<a href="{{ clear_search_url }}" class="input-group-addon clear"><span class="fa fa-times glyphicon glyphicon-remove"></span></a>
</div>
{% else %}
<div class="form-group">
<input type="text" name="search" value="" class="{{ input_class }} form-control" placeholder="{{ _gettext('Search') }}">
<input type="text" name="search" value="" class="{{ input_class }} form-control" placeholder="{{ _gettext('%(placeholder)s', placeholder=search_placeholder) }}">
</div>
{% endif %}
</form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment