search: add a placeholder attribute to search input cell (#40993)
This commit is contained in:
parent
4993fc23e5
commit
14aa0b62fe
|
@ -25,7 +25,7 @@ from .models import SearchCell
|
|||
class SearchCellForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = SearchCell
|
||||
fields = ('_search_services', 'autofocus')
|
||||
fields = ('_search_services', 'autofocus', 'input_placeholder')
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(SearchCellForm, self).__init__(*args, **kwargs)
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.18 on 2020-04-08 17:22
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('search', '0007_french_fts'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='searchcell',
|
||||
name='input_placeholder',
|
||||
field=models.CharField(blank=True, default='', max_length=64, verbose_name='Placeholder'),
|
||||
),
|
||||
]
|
|
@ -44,6 +44,7 @@ class SearchCell(CellBase):
|
|||
|
||||
_search_services = JSONField(_('Search Services'), default=dict, blank=True)
|
||||
autofocus = models.BooleanField(_('Autofocus'), default=False)
|
||||
input_placeholder = models.CharField(_('Placeholder'), max_length=64, default="", blank=True)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('Search')
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
{% block search-form %}
|
||||
<form id="combo-search-form-{{ cell.pk }}" class="combo-search-form">
|
||||
<input type="search" name="q" autocomplete="off" id="combo-search-input-{{ cell.pk }}" class="combo-search-input" {% if cell.autofocus %}autofocus {% endif %}/>
|
||||
<input type="search" name="q" autocomplete="off" id="combo-search-input-{{ cell.pk }}" class="combo-search-input" {% if cell.autofocus %}autofocus {% endif %}{% if cell.input_placeholder %}placeholder="{{ cell.input_placeholder }}" {% endif %}/>
|
||||
<button class="submit-button" aria-label="{% trans 'Search' %}">{% block submit-content %}{% trans 'Search' %}{% endblock %}</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
|
|
@ -61,12 +61,14 @@ def test_search_cell(app):
|
|||
|
||||
cell = SearchCell(page=page, placeholder='content', order=0)
|
||||
cell._search_services = {'data': ['search1']}
|
||||
cell.input_placeholder = 'my placeholder'
|
||||
cell.save()
|
||||
|
||||
resp = cell.render({})
|
||||
assert 'input' in resp
|
||||
assert 'id="combo-search-input-%s"' % cell.pk in resp
|
||||
assert 'autofocus' not in resp
|
||||
assert 'placeholder="my placeholder"' in resp
|
||||
|
||||
cell.autofocus = True
|
||||
cell.save()
|
||||
|
@ -375,6 +377,7 @@ def test_manager_search_cell(app, admin_user):
|
|||
(u'_text', False, u'Page Contents'),
|
||||
(u'search1', False, u'Search 1')]
|
||||
resp.form['c%s-_search_services' % cells[0].get_reference()].value = ['search_tmpl', '_text']
|
||||
resp.form['c%s-input_placeholder' % cells[0].get_reference()] = 'my placeholder'
|
||||
resp = resp.form.submit()
|
||||
assert resp.status_int == 302
|
||||
|
||||
|
@ -384,6 +387,9 @@ def test_manager_search_cell(app, admin_user):
|
|||
assert resp.form['c%s-_search_services' % cells[0].get_reference()].options[0][0] == 'search_tmpl'
|
||||
assert resp.form['c%s-_search_services' % cells[0].get_reference()].options[1][0] == '_text'
|
||||
|
||||
# check placeholder
|
||||
resp.form['c%s-input_placeholder' % cells[0].get_reference()] == 'my placeholder'
|
||||
|
||||
# check there's no crash if search engines are removed from config
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
assert resp.form['c%s-_search_services' % cells[0].get_reference()].value == ['_text']
|
||||
|
|
Loading…
Reference in New Issue