Commit 1f14a3e3 authored by Paul Brown's avatar Paul Brown

fix order of inline editable select field items and fix inline editable relation fields

parent 45e2b81e
...@@ -113,7 +113,13 @@ class XEditableWidget(object): ...@@ -113,7 +113,13 @@ class XEditableWidget(object):
kwargs['data-role'] = 'x-editable-boolean' kwargs['data-role'] = 'x-editable-boolean'
elif subfield.type == 'Select2Field': elif subfield.type == 'Select2Field':
kwargs['data-type'] = 'select' kwargs['data-type'] = 'select'
kwargs['data-source'] = dict(subfield.choices) choices = [{'value': x, 'text': y} for x, y in subfield.choices]
kwargs['data-source'] = choices
# prepend a blank field to choices if allow_blank = True
if getattr(subfield, 'allow_blank', False):
kwargs['data-source'].insert(0, {'value': '__None',
'text': ''})
elif subfield.type == 'DateField': elif subfield.type == 'DateField':
kwargs['data-type'] = 'combodate' kwargs['data-type'] = 'combodate'
kwargs['data-format'] = 'YYYY-MM-DD' kwargs['data-format'] = 'YYYY-MM-DD'
...@@ -135,20 +141,21 @@ class XEditableWidget(object): ...@@ -135,20 +141,21 @@ class XEditableWidget(object):
kwargs['data-type'] = 'number' kwargs['data-type'] = 'number'
kwargs['data-step'] = 'any' kwargs['data-step'] = 'any'
elif subfield.type in ['QuerySelectField', 'ModelSelectField']: elif subfield.type in ['QuerySelectField', 'ModelSelectField']:
# QuerySelectField and ModelSelectField are for relations
kwargs['data-type'] = 'select' kwargs['data-type'] = 'select'
choices = {} choices = []
for choice in subfield: for choice in subfield:
try: try:
choices[str(choice._value())] = str(choice.label.text) choices.append({'value': str(choice._value()),
'text': str(choice.label.text)})
except TypeError: except TypeError:
choices[str(choice._value())] = "" # unable to display text value
choices.append({'value': str(choice._value()), 'text': ''})
# includes blank field if allow_blank
kwargs['data-source'] = choices kwargs['data-source'] = choices
else: else:
raise Exception('Unsupported field type: %s' % (type(subfield),)) raise Exception('Unsupported field type: %s' % (type(subfield),))
# for Select2, QuerySelectField, and ModelSelectField
if getattr(subfield, 'allow_blank', False):
kwargs['data-source']['__None'] = ""
return kwargs return kwargs
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