Commit 2d5f7c0c authored by Fayaz Yusuf Khan's avatar Fayaz Yusuf Khan

use select2 in editable columns

parent f04b71b7
...@@ -93,6 +93,7 @@ For all the tests to pass successfully, you'll need Postgres & MongoDB to be run ...@@ -93,6 +93,7 @@ For all the tests to pass successfully, you'll need Postgres & MongoDB to be run
CREATE DATABASE flask_admin_test; CREATE DATABASE flask_admin_test;
CREATE EXTENSION postgis; CREATE EXTENSION postgis;
CREATE EXTENSION hstore;
You can also run the tests on multiple environments using *tox*. You can also run the tests on multiple environments using *tox*.
......
...@@ -72,7 +72,8 @@ class XEditableWidget(object): ...@@ -72,7 +72,8 @@ class XEditableWidget(object):
field inside of the FieldList (StringField, IntegerField, etc). field inside of the FieldList (StringField, IntegerField, etc).
""" """
def __call__(self, field, **kwargs): def __call__(self, field, **kwargs):
kwargs.setdefault('data-value', kwargs.pop('display_value', '')) display_value = kwargs.pop('display_value', '')
kwargs.setdefault('data-value', display_value)
kwargs.setdefault('data-role', 'x-editable') kwargs.setdefault('data-role', 'x-editable')
kwargs.setdefault('data-url', './ajax/update/') kwargs.setdefault('data-url', './ajax/update/')
...@@ -91,7 +92,7 @@ class XEditableWidget(object): ...@@ -91,7 +92,7 @@ class XEditableWidget(object):
return HTMLString( return HTMLString(
'<a %s>%s</a>' % (html_params(**kwargs), '<a %s>%s</a>' % (html_params(**kwargs),
escape(kwargs['data-value'])) escape(display_value))
) )
def get_kwargs(self, field, kwargs): def get_kwargs(self, field, kwargs):
...@@ -104,7 +105,7 @@ class XEditableWidget(object): ...@@ -104,7 +105,7 @@ class XEditableWidget(object):
kwargs['data-type'] = 'textarea' kwargs['data-type'] = 'textarea'
kwargs['data-rows'] = '5' kwargs['data-rows'] = '5'
elif field.type == 'BooleanField': elif field.type == 'BooleanField':
kwargs['data-type'] = 'select' kwargs['data-type'] = 'select2'
# data-source = dropdown options # data-source = dropdown options
kwargs['data-source'] = json.dumps([ kwargs['data-source'] = json.dumps([
{'value': '', 'text': gettext('No')}, {'value': '', 'text': gettext('No')},
...@@ -112,7 +113,7 @@ class XEditableWidget(object): ...@@ -112,7 +113,7 @@ class XEditableWidget(object):
]) ])
kwargs['data-role'] = 'x-editable-boolean' kwargs['data-role'] = 'x-editable-boolean'
elif field.type in ['Select2Field', 'SelectField']: elif field.type in ['Select2Field', 'SelectField']:
kwargs['data-type'] = 'select' kwargs['data-type'] = 'select2'
choices = [{'value': x, 'text': y} for x, y in field.choices] choices = [{'value': x, 'text': y} for x, y in field.choices]
# prepend a blank field to choices if allow_blank = True # prepend a blank field to choices if allow_blank = True
...@@ -144,7 +145,7 @@ class XEditableWidget(object): ...@@ -144,7 +145,7 @@ class XEditableWidget(object):
elif field.type in ['QuerySelectField', 'ModelSelectField', elif field.type in ['QuerySelectField', 'ModelSelectField',
'QuerySelectMultipleField', 'KeyPropertyField']: 'QuerySelectMultipleField', 'KeyPropertyField']:
# QuerySelectField and ModelSelectField are for relations # QuerySelectField and ModelSelectField are for relations
kwargs['data-type'] = 'select' kwargs['data-type'] = 'select2'
choices = [] choices = []
selected_ids = [] selected_ids = []
...@@ -162,12 +163,13 @@ class XEditableWidget(object): ...@@ -162,12 +163,13 @@ class XEditableWidget(object):
kwargs['data-source'] = json.dumps(choices) kwargs['data-source'] = json.dumps(choices)
if field.type == 'QuerySelectMultipleField': if field.type == 'QuerySelectMultipleField':
kwargs['data-type'] = 'select2'
kwargs['data-role'] = 'x-editable-select2-multiple' kwargs['data-role'] = 'x-editable-select2-multiple'
# must use id instead of text or prefilled values won't work # must use id instead of text or prefilled values won't work
separator = getattr(field, 'separator', ',') separator = getattr(field, 'separator', ',')
kwargs['data-value'] = separator.join(selected_ids) kwargs['data-value'] = separator.join(selected_ids)
else:
kwargs['data-value'] = text_type(selected_ids[0])
else: else:
raise Exception('Unsupported field type: %s' % (type(field),)) raise Exception('Unsupported field type: %s' % (type(field),))
......
...@@ -139,3 +139,7 @@ table.filters tr td { ...@@ -139,3 +139,7 @@ table.filters tr td {
*/ */
#no-more-tables td:before { content: attr(data-title); } #no-more-tables td:before { content: attr(data-title); }
} }
.editable-input .select2-container {
min-width: 220px;
}
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