provide special dropdown field instance in order to correctly display vocabulary values; make field instance lookabe more tolerant: use default field instance if named adapter not found
This commit is contained in:
parent
5c42607915
commit
5190ebb728
3 changed files with 18 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
|
||||
# Copyright (c) 2011 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -142,7 +142,9 @@ class Field(Component):
|
|||
|
||||
def getFieldInstance(self, clientInstance=None):
|
||||
instanceName = self.instance_name or self.getFieldTypeInfo().instanceName
|
||||
fi = component.getAdapter(self, IFieldInstance, name=instanceName)
|
||||
fi = component.queryAdapter(self, IFieldInstance, name=instanceName)
|
||||
if fi is None:
|
||||
fi = component.getAdapter(self, IFieldInstance, name='')
|
||||
fi.clientInstance = clientInstance
|
||||
return fi
|
||||
|
||||
|
@ -361,3 +363,14 @@ class CheckBoxesFieldInstance(ListFieldInstance):
|
|||
|
||||
def ummarshal(self, value):
|
||||
return value
|
||||
|
||||
|
||||
class DropdownFieldInstance(FieldInstance):
|
||||
|
||||
def display(self, value):
|
||||
items = self.context.getVocabularyItems()
|
||||
for item in items:
|
||||
if item['token'] == value:
|
||||
return item['title']
|
||||
return value
|
||||
|
||||
|
|
|
@ -107,7 +107,8 @@ fieldTypes = SimpleVocabulary((
|
|||
FieldType('fileupload', 'fileupload', u'File upload',
|
||||
instanceName='fileupload'),
|
||||
FieldType('checkbox', 'checkbox', u'Checkbox', instanceName='boolean'),
|
||||
FieldType('dropdown', 'dropdown', u'Drop-down selection'),
|
||||
FieldType('dropdown', 'dropdown', u'Drop-down selection',
|
||||
instanceName='dropdown'),
|
||||
FieldType('radiobuttons', 'radiobuttons', u'Radiobutton Group'),
|
||||
#FieldType('listbox', 'listbox', u'List box (multiple selection)'),
|
||||
FieldType('list', 'list', u'List', instanceName='list'),
|
||||
|
|
|
@ -30,6 +30,7 @@ def setUp(site):
|
|||
component.provideAdapter(field.FieldInstance)
|
||||
component.provideAdapter(field.NumberFieldInstance, name='number')
|
||||
component.provideAdapter(field.EmailFieldInstance, name='email')
|
||||
#component.provideAdapter(field.DropdownFieldInstance, name='dropdown')
|
||||
component.provideAdapter(service.StatefulRegistration)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue