Fixed #29221 -- Corrected admin's autocomplete widget to add a space after custom classes.

This commit is contained in:
Artem Tabolin 2018-03-15 15:55:34 +01:00 committed by Tim Graham
parent ba3078c92d
commit a2f7433adc
3 changed files with 10 additions and 2 deletions

View File

@ -413,7 +413,7 @@ class AutocompleteMixin:
'data-theme': 'admin-autocomplete',
'data-allow-clear': json.dumps(not self.is_required),
'data-placeholder': '', # Allows clearing of the input.
'class': attrs['class'] + 'admin-autocomplete',
'class': attrs['class'] + (' ' if attrs['class'] else '') + 'admin-autocomplete',
})
return attrs

View File

@ -14,3 +14,6 @@ Bugfixes
* Fixed admin autocomplete widget's translations for `zh-hans` and `zh-hant`
languages (:ticket:`29213`).
* Corrected admin's autocomplete widget to add a space after custom classes
(:ticket:`29221`).

View File

@ -50,7 +50,7 @@ class AutocompleteMixinTests(TestCase):
form = AlbumForm()
attrs = form['band'].field.widget.get_context(name='my_field', value=None, attrs={})['widget']['attrs']
self.assertEqual(attrs, {
'class': 'my-classadmin-autocomplete',
'class': 'my-class admin-autocomplete',
'data-ajax--cache': 'true',
'data-ajax--type': 'GET',
'data-ajax--url': '/admin_widgets/band/autocomplete/',
@ -59,6 +59,11 @@ class AutocompleteMixinTests(TestCase):
'data-placeholder': ''
})
def test_build_attrs_no_custom_class(self):
form = AlbumForm()
attrs = form['featuring'].field.widget.get_context(name='name', value=None, attrs={})['widget']['attrs']
self.assertEqual(attrs['class'], 'admin-autocomplete')
def test_build_attrs_not_required_field(self):
form = NotRequiredBandForm()
attrs = form['band'].field.widget.build_attrs({})