[Checkins] SVN: z3c.formext/branches/sagblmi-morecomponent/s Refactor IExtjsComponent adapter
Laurent Mignon
Laurent.Mignon at softwareag.com
Thu Feb 26 12:26:13 EST 2009
Log message for revision 97328:
Refactor IExtjsComponent adapter
Add support for a lot of widgets
Changed:
U z3c.formext/branches/sagblmi-morecomponent/setup.py
U z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.py
U z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.txt
A z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.zcml
U z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/configure.zcml
U z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/interfaces.py
U z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/resources/form-script.js
U z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/resources/z3c.formext.loader.js
U z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/testing.py
A z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/tests/interfaces.py
-=-
Modified: z3c.formext/branches/sagblmi-morecomponent/setup.py
===================================================================
--- z3c.formext/branches/sagblmi-morecomponent/setup.py 2009-02-26 17:23:16 UTC (rev 97327)
+++ z3c.formext/branches/sagblmi-morecomponent/setup.py 2009-02-26 17:26:13 UTC (rev 97328)
@@ -53,6 +53,7 @@
'z3c.coverage',
'z3c.template',
'zope.app.i18n',
+ 'z3c.form [test]',
],
adding = ['zope.app.container'],
),
Modified: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.py
===================================================================
--- z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.py 2009-02-26 17:23:16 UTC (rev 97327)
+++ z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.py 2009-02-26 17:26:13 UTC (rev 97328)
@@ -19,14 +19,18 @@
import zope.interface
import zope.component
+import zope.schema.interfaces
from zope.traversing.browser.absoluteurl import absoluteURL
+from z3c.form.interfaces import IDataConverter
from z3c.form.interfaces import IForm, DISPLAY_MODE, HIDDEN_MODE
-from z3c.form.interfaces import IPasswordWidget, IRadioWidget, IButtonAction
+from z3c.form.interfaces import IRadioWidget, IButtonAction
+from z3c.form.interfaces import IWidget
from z3c.form.interfaces import ITextAreaWidget
from z3c.form.interfaces import ITextWidget
from z3c.form.interfaces import ISelectWidget
from z3c.form.interfaces import ISingleCheckBoxWidget
+from z3c.form.interfaces import IFormLayer
from z3c.formext import interfaces
from z3c.formext.jsoncompat import jsonEncode
@@ -47,8 +51,12 @@
xtype = None
- def __init__(self, widget):
+ def __init__(self, context, request, form, widget, field):
+ self.context = context
+ self.request = request
+ self.form = form
self.widget = widget
+ self.field = field
def _getConfig(self):
config = dict(
@@ -58,78 +66,176 @@
value = self.widget.value)
if self.xtype:
config['xtype'] = self.xtype
+ title = self.widget.title
if self.widget.title:
config['title'] = self.widget.title
if self.widget.mode == DISPLAY_MODE:
config['disabled'] = True
if self.widget.mode == HIDDEN_MODE:
config['hidden'] = True
+ if self.widget.required:
+ config['itemCls'] = 'required'
return config
class TextField(Field):
zope.interface.implements(interfaces.IExtJSComponent)
- zope.component.adapts(ITextWidget)
+ zope.component.adapts(
+ zope.interface.Interface,
+ IFormLayer,
+ IForm,
+ ITextWidget,
+ zope.schema.interfaces.IField)
xtype = 'textfield'
def _getConfig(self, json=False):
config = super(TextField, self)._getConfig()
- if IPasswordWidget.providedBy(self.widget):
- config['inputType'] = 'password'
+ config['allowBlank'] = not self.widget.required
+ if zope.schema.interfaces.IMinMaxLen.providedBy(self.field):
+ if self.field.min_length is not None:
+ config['minLength'] = self.field.min_length
+ if self.field.max_length is not None:
+ config['maxLength'] = self.field.max_length
+ if zope.schema.interfaces.IMinMax.providedBy(self.field):
+ converter = IDataConverter(self.widget)
+ if self.field.min is not None:
+ config['minValue'] = converter.toWidgetValue(self.field.min)
+ if self.field.max is not None:
+ config['maxValue'] = converter.toWidgetValue(self.field.max)
return config
+class DateField(TextField):
+ zope.interface.implements(interfaces.IExtJSComponent)
+ zope.component.adapts(
+ zope.interface.Interface,
+ IFormLayer,
+ IForm,
+ ITextWidget,
+ zope.schema.interfaces.IDate)
+
+ xtype = 'datefield'
+
+
+class TimeField(TextField):
+ zope.interface.implements(interfaces.IExtJSComponent)
+ zope.component.adapts(
+ zope.interface.Interface,
+ IFormLayer,
+ IForm,
+ ITextWidget,
+ zope.schema.interfaces.ITime)
+
+ xtype = 'timefield'
+
+class NumberField(TextField):
+ zope.interface.implements(interfaces.IExtJSComponent)
+ zope.component.adapts(
+ zope.interface.Interface,
+ IFormLayer,
+ IForm,
+ ITextWidget,
+ zope.schema.interfaces.IField)
+ xtype = 'numberfield'
+
+ def _getConfig(self, json=False):
+ config = super(NumberField, self)._getConfig()
+ config['allowDecimals'] = \
+ not zope.schema.interfaces.IInt.providedBy(self.field)
+ return config
+
+
+class Password(TextField):
+ zope.interface.implements(interfaces.IExtJSComponent)
+ zope.component.adapts(
+ zope.interface.Interface,
+ IFormLayer,
+ IForm,
+ ITextWidget,
+ zope.schema.interfaces.IPassword)
+
+ def _getConfig(self, json=False):
+ config = super(Password, self)._getConfig()
+ config['inputType'] = 'password'
+ return config
+
+
class TextArea(TextField):
zope.interface.implements(interfaces.IExtJSComponent)
- zope.component.adapts(ITextAreaWidget)
+ zope.component.adapts(
+ zope.interface.Interface,
+ IFormLayer,
+ IForm,
+ ITextAreaWidget,
+ zope.schema.interfaces.IField)
xtype = 'textarea'
-class DateField(TextField):
+class DateWidget(DateField):
zope.interface.implements(interfaces.IExtJSComponent)
- zope.component.adapts(interfaces.IExtJSDateWidget)
+ zope.component.adapts(
+ zope.interface.Interface,
+ IFormLayer,
+ IForm,
+ interfaces.IExtJSDateWidget,
+ zope.schema.interfaces.IDate)
- xtype = 'datefield'
-
class ComboBox(Field):
zope.interface.implements(interfaces.IExtJSComponent)
- zope.component.adapts(ISelectWidget)
+ zope.component.adapts(
+ zope.interface.Interface,
+ IFormLayer,
+ IForm,
+ ISelectWidget,
+ zope.schema.interfaces.IChoice)
xtype = 'combo'
def _getConfig(self, json=False):
config = super(ComboBox, self)._getConfig()
- config['hiddenName'] = config['name']+':list'
- config['triggerAction'] = 'all'
- config['editable'] = False
- #XXX: commented out, not sure why this was here
- #del config['name']
- config['store'] = [(item['value'], item['content'])
- for item in self.widget.items]
+ config.update(dict(
+ hiddenName = config['name']+':list',
+ triggerAction = 'all',
+ editable = False,
+ store= [(item['value'], item['content'])
+ for item in self.widget.items],
+ ))
return config
class CheckBox(Field):
zope.interface.implements(interfaces.IExtJSComponent)
- zope.component.adapts(ISingleCheckBoxWidget)
+ zope.component.adapts(
+ zope.interface.Interface,
+ IFormLayer,
+ IForm,
+ ISingleCheckBoxWidget,
+ zope.schema.interfaces.IField)
xtype = 'checkbox'
def _getConfig(self, json=False):
config = super(CheckBox, self)._getConfig()
checkbox = self.widget.items[0]
- config['checked'] = checkbox['checked']
- config['fieldLabel'] = checkbox['label']
+ config.update(dict(
+ checked = checkbox['checked'],
+ fieldLabel = checkbox['label'],
+ ))
del config['value']
return config
class RadioGroup(Field):
zope.interface.implements(interfaces.IExtJSComponent)
- zope.component.adapts(IRadioWidget)
+ zope.component.adapts(
+ zope.interface.Interface,
+ IFormLayer,
+ IForm,
+ IRadioWidget,
+ zope.schema.interfaces.IField)
def _getConfig(self, json=False):
config = dict(
@@ -153,12 +259,24 @@
return config
+ at zope.component.adapter(IWidget)
+ at zope.interface.implementer(interfaces.IExtJSComponent)
+def SimpleFiedWidgetFactory(widget):
+ return zope.component.getMultiAdapter(
+ (widget.context, widget.request, widget.form,
+ widget, widget.field),
+ interfaces.IExtJSComponent)
+
+
class Button(Field):
zope.interface.implements(interfaces.IExtJSComponent)
zope.component.adapts(IButtonAction)
xtype = 'button'
+ def __init__(self, widget):
+ super(Button, self).__init__(None, None, None, widget, None)
+
def _getConfig(self, json=False):
config = super(Button, self)._getConfig()
config['text'] = self.widget.value
@@ -177,21 +295,38 @@
for name, action in form.actions.items()])
+def getWidgetConfig(widget):
+ """Get the wiget as a json serializable object
+ """
+ component = None
+ #first try to get the componentFactory from the widget
+ factory = getattr(widget, 'componentFactory', None)
+ if factory is not None:
+ component = factory(widget.context, widget.request,
+ widget.form, widget, widget.field)
+ #if not provided try to get one from the registry
+ if component is None:
+ component = zope.component.queryMultiAdapter(
+ (widget.context, widget.request,
+ widget.form, widget, widget.field),
+ interfaces.IExtJSComponent)
+ #fallback to a simple adapter
+ if component is None:
+ component = interfaces.IExtJSComponent(widget)
+ return component.getConfig()
+
+
def getWidgetsConfig(form, asDict=True):
if not asDict:
widgets = []
for widget in form.widgets.values():
- factory = interfaces.IExtJSComponent
- if hasattr(widget, 'componentFactory'):
- factory = widget.componentFactory
- widgets.append(factory(widget).getConfig())
+ config = getWidgetConfig(widget)
+ widgets.append(config)
return widgets
widgets = {}
for name, widget in form.widgets.items():
- factory = interfaces.IExtJSComponent
- if hasattr(widget, 'componentFactory'):
- factory = widget.componentFactory
- widgets[name] = factory(widget).getConfig()
+ config = getWidgetConfig(widget)
+ widgets[name] = config
return widgets
Modified: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.txt
===================================================================
--- z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.txt 2009-02-26 17:23:16 UTC (rev 97327)
+++ z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.txt 2009-02-26 17:26:13 UTC (rev 97328)
@@ -4,7 +4,7 @@
We can construct configuration objects for basic extjs components.
- >>> from z3c.formext import interfaces, component, testing
+ >>> from z3c.formext import interfaces, testing
>>> from pprint import pprint
@@ -19,158 +19,519 @@
Widgets
-------
-TextWidget
+ >>> from z3c.form.interfaces import HIDDEN_MODE, DISPLAY_MODE, IFieldWidget
+ >>> from z3c.form.browser.text import TextWidget
+
+ >>> widget = TextWidget(TestRequest())
+ >>> widget.label = u'Widget Label'
+ >>> widget.id = 'widget-id'
+ >>> widget.name = 'widget.name'
+ >>> widget.value = 'widget value'
+ >>> pprint(interfaces.IExtJSComponent(widget).getConfig())
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: ... <InterfaceClass z3c.formext.interfaces.IExtJSComponent>, u'')
+
+A widget provides a representation for a field. Since the representation
+depends on the field itself, we need to associate a field to the widget to get
+the right configuration. Let's create a field first:
+
+ >>> import zope.schema
+ >>> labelField = zope.schema.TextLine(
+ ... __name__ = 'label',
+ ... title = u'Label title')
+
+We associate the widget and the field
+
+ >>> import z3c.form.widget
+ >>> labelWidget = z3c.form.widget.FieldWidget(labelField, widget)
+ >>> labelWidget
+ <TextWidget 'label'>
+
+Of course, this is more commonly done using an adapter:
+ >>> request = TestRequest()
+ >>> labelWidget = zope.component.getMultiAdapter((labelField, request),
+ ... IFieldWidget)
+ >>> labelWidget
+ <TextWidget 'label'>
+ >>> labelWidget.update()
+
+We can now get the configuration
+
+ >>> pprint(interfaces.IExtJSComponent(labelWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Label title',
+ 'id': 'label',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'label',
+ 'value': u'',
+ 'xtype': 'textfield'}
+
+ >>> labelWidget.request = TestRequest(form = {'label': 'widget value'})
+ >>> labelWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(labelWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Label title',
+ 'id': 'label',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'label',
+ 'value': 'widget value',
+ 'xtype': 'textfield'}
+
+ >>> labelWidget.mode = HIDDEN_MODE
+ >>> pprint(interfaces.IExtJSComponent(labelWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Label title',
+ 'hidden': True,
+ 'id': 'label',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'label',
+ 'value': 'widget value',
+ 'xtype': 'textfield'}
+
+ >>> labelWidget.mode = DISPLAY_MODE
+ >>> pprint(interfaces.IExtJSComponent(labelWidget).getConfig())
+ {'allowBlank': False,
+ 'disabled': True,
+ 'fieldLabel': u'Label title',
+ 'id': 'label',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'label',
+ 'value': 'widget value',
+ 'xtype': 'textfield'}
+
+Off course, the config also provides constrains specific to the field.
+
+ >>> labelField.min_length = 1
+ >>> labelField.max_length = 200
+ >>> labelField.required = False
+ >>> labelWidget = zope.component.getMultiAdapter((labelField, request),
+ ... IFieldWidget)
+ >>> pprint(interfaces.IExtJSComponent(labelWidget).getConfig())
+ {'allowBlank': True,
+ 'fieldLabel': u'Label title',
+ 'id': 'label',
+ 'maxLength': 200,
+ 'minLength': 1,
+ 'name': 'label',
+ 'value': u'',
+ 'xtype': 'textfield'}
+
+Let's test config for a lot of possible fields
+ >>> from z3c.formext.tests.interfaces import IAllFields
+
+ASCIIWidget
+...........
+
+ >>> asciiWidget = zope.component.queryMultiAdapter(
+ ... (IAllFields['asciiField'], request),
+ ... IFieldWidget)
+ >>> asciiWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(asciiWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'ASCII',
+ 'id': 'asciiField',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'asciiField',
+ 'value': u'This is\n ASCII.',
+ 'xtype': 'textarea'}
+
+ASCIILineWidget
+...............
+
+ >>> asciiLineWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['asciiLineField'], request),
+ ... IFieldWidget)
+ >>> asciiLineWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(asciiLineWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'ASCII Line',
+ 'id': 'asciiLineField',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'asciiLineField',
+ 'value': u'An ASCII line.',
+ 'xtype': 'textfield'}
+
+BOOLWidget
..........
- >>> from z3c.form.interfaces import HIDDEN_MODE, DISPLAY_MODE
- >>> from z3c.form.browser.text import TextWidget
+ >>> boolWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['boolField'], request),
+ ... IFieldWidget)
+ >>> boolWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(boolWidget).getConfig())
+ {'fieldLabel': u'Boolean',
+ 'id': 'boolField',
+ 'items': [{'boxLabel': u'yes',
+ 'checked': True,
+ 'id': 'boolField-0',
+ 'inputValue': 'true',
+ 'name': 'boolField'},
+ {'boxLabel': u'no',
+ 'checked': False,
+ 'id': 'boolField-1',
+ 'inputValue': 'false',
+ 'name': 'boolField'}],
+ 'xtype': 'radiogroup'}
- >>> widget = TextWidget(TestRequest())
- >>> widget.label = u'Widget Label'
- >>> widget.id = 'widget-id'
- >>> widget.name = 'widget.name'
- >>> widget.value = 'widget value'
+BytesFied (TODO)
+................
- >>> pprint(interfaces.IExtJSComponent(widget).getConfig())
- {'fieldLabel': u'Widget Label',
- 'id': 'widget-id',
- 'name': 'widget.name',
- 'value': 'widget value',
- 'xtype': 'textfield'}
+ >>> bytesWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['bytesField'], request),
+ ... IFieldWidget)
+ >>> bytesWidget.update()
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: ...
+ >>> pprint(interfaces.IExtJSComponent(bytesWidget).getConfig())
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: ... <InterfaceClass z3c.formext.interfaces.IExtJSComponent>, u'')
- >>> widget.mode = HIDDEN_MODE
- >>> pprint(interfaces.IExtJSComponent(widget).getConfig())
- {'fieldLabel': u'Widget Label',
- 'hidden': True,
- 'id': 'widget-id',
- 'name': 'widget.name',
- 'value': 'widget value',
- 'xtype': 'textfield'}
- >>> widget.mode = DISPLAY_MODE
- >>> pprint(interfaces.IExtJSComponent(widget).getConfig())
- {'disabled': True,
- 'fieldLabel': u'Widget Label',
- 'id': 'widget-id',
- 'name': 'widget.name',
- 'value': 'widget value',
- 'xtype': 'textfield'}
+BytesLineFied
+.............
-TextArea
+ >>> bytesLineWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['bytesLineField'], request),
+ ... IFieldWidget)
+ >>> bytesLineWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(bytesLineWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Bytes Line',
+ 'id': 'bytesLineField',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'bytesLineField',
+ 'value': u'A Bytes line.',
+ 'xtype': 'textfield'}
+
+
+ChoiceField
+...........
+
+ >>> choiceWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['choiceField'], request),
+ ... IFieldWidget)
+ >>> choiceWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(choiceWidget).getConfig())
+ {'editable': False,
+ 'fieldLabel': u'Choice',
+ 'hiddenName': 'choiceField:list',
+ 'id': 'choiceField',
+ 'itemCls': 'required',
+ 'name': 'choiceField',
+ 'store': [('1', u'One'),
+ ('2', u'Two'),
+ ('3', u'Three'),
+ ('4', u'Four'),
+ ('5', u'Five')],
+ 'triggerAction': 'all',
+ 'value': ['3'],
+ 'xtype': 'combo'}
+
+Works also with optional choice
+
+ >>> choiceWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['optionalChoiceField'], request),
+ ... IFieldWidget)
+ >>> choiceWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(choiceWidget).getConfig())
+ {'editable': False,
+ 'fieldLabel': u'Choice (Not Required)',
+ 'hiddenName': 'optionalChoiceField:list',
+ 'id': 'optionalChoiceField',
+ 'name': 'optionalChoiceField',
+ 'store': [('--NOVALUE--', u'no value'),
+ ('1', u'One'),
+ ('2', u'Two'),
+ ('3', u'Three'),
+ ('4', u'Four'),
+ ('5', u'Five')],
+ 'triggerAction': 'all',
+ 'value': (),
+ 'xtype': 'combo'}
+
+DateField
+.........
+
+ >>> dateWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['dateField'], request),
+ ... IFieldWidget)
+ >>> dateWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(dateWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Date',
+ 'id': 'dateField',
+ 'itemCls': 'required',
+ 'name': 'dateField',
+ 'value': u'07/04/01',
+ 'xtype': 'datefield'}
+
+
+DatetimeField
+.............
+
+DateTime field has no specific widget. It use the textfield widget
+
+ >>> datetimeWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['datetimeField'], request),
+ ... IFieldWidget)
+ >>> datetimeWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(datetimeWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Date/Time',
+ 'id': 'datetimeField',
+ 'itemCls': 'required',
+ 'name': 'datetimeField',
+ 'value': u'07/04/01 12:00',
+ 'xtype': 'textfield'}
+
+DecimalField
+.............
+
+ >>> decimalWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['decimalField'], request),
+ ... IFieldWidget)
+ >>> decimalWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(decimalWidget).getConfig())
+ {'allowBlank': False,
+ 'allowDecimals': True,
+ 'fieldLabel': u'Decimal',
+ 'id': 'decimalField',
+ 'itemCls': 'required',
+ 'name': 'decimalField',
+ 'value': u'12.87',
+ 'xtype': 'numberfield'}
+
+DottedNameField
+...............
+
+ >>> dottedNameWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['dottedNameField'], request),
+ ... IFieldWidget)
+ >>> dottedNameWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(dottedNameWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Dotted Name',
+ 'id': 'dottedNameField',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'dottedNameField',
+ 'value': u'z3c.form',
+ 'xtype': 'textfield'}
+
+FloatField
+..........
+
+ >>> floatWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['floatField'], request),
+ ... IFieldWidget)
+ >>> floatWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(floatWidget).getConfig())
+ {'allowBlank': False,
+ 'allowDecimals': True,
+ 'fieldLabel': u'Float',
+ 'id': 'floatField',
+ 'itemCls': 'required',
+ 'name': 'floatField',
+ 'value': u'12.8',
+ 'xtype': 'numberfield'}
+
+FrozenSetField (TODO)
+.....................
+
+ >>> frozenSetWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['frozenSetField'], request),
+ ... IFieldWidget)
+ >>> frozenSetWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(frozenSetWidget).getConfig())
+ Traceback (most recent call last):
+ ...
+ ComponentLookupError: ... <InterfaceClass z3c.formext.interfaces.IExtJSComponent>, u'')
+
+
+IdField
+.......
+
+ >>> idWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['idField'], request),
+ ... IFieldWidget)
+ >>> idWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(idWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Id',
+ 'id': 'idField',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'idField',
+ 'value': u'z3c.form',
+ 'xtype': 'textfield'}
+
+IntField
........
+ >>> intWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['intField'], request),
+ ... IFieldWidget)
+ >>> intWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(intWidget).getConfig())
+ {'allowBlank': False,
+ 'allowDecimals': False,
+ 'fieldLabel': u'Integer',
+ 'id': 'intField',
+ 'itemCls': 'required',
+ 'name': 'intField',
+ 'value': u'12,345',
+ 'xtype': 'numberfield'}
- >>> from z3c.form.browser.textarea import TextAreaWidget
+ListField
+.........
- >>> widget = TextAreaWidget(TestRequest())
- >>> widget.label = u'Widget Label'
- >>> widget.id = 'widget-id'
- >>> widget.name = 'widget.name'
- >>> widget.value = 'widget value'
+TODO
- >>> pprint(interfaces.IExtJSComponent(widget).getConfig())
- {'fieldLabel': u'Widget Label',
- 'id': 'widget-id',
- 'name': 'widget.name',
- 'value': 'widget value',
- 'xtype': 'textarea'}
-
-Date Widget
+ObjectField
...........
- >>> from z3c.formext.widget import ExtJSDateWidget
+TODO
- >>> widget = ExtJSDateWidget(TestRequest())
- >>> widget.label = u'Widget Label'
- >>> widget.id = 'widget-id'
- >>> widget.name = 'widget.name'
- >>> widget.value = 'widget value'
+PasswordField
+.............
+
+ >>> passwordWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['passwordField'], request),
+ ... IFieldWidget)
+ >>> passwordWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(passwordWidget).getConfig())
+ {'allowBlank': True,
+ 'fieldLabel': u'Password',
+ 'id': 'passwordField',
+ 'inputType': 'password',
+ 'minLength': 0,
+ 'name': 'passwordField',
+ 'value': u'mypwd',
+ 'xtype': 'textfield'}
- >>> pprint(interfaces.IExtJSComponent(widget).getConfig())
- {'fieldLabel': u'Widget Label',
- 'id': 'widget-id',
- 'name': 'widget.name',
- 'value': 'widget value',
- 'xtype': 'datefield'}
+setField
+........
-Select Widget
+TODO
+
+SourceTextField
+...............
+
+ >>> sourceTextWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['sourceTextField'], request),
+ ... IFieldWidget)
+ >>> sourceTextWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(sourceTextWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Source Text',
+ 'id': 'sourceTextField',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'sourceTextField',
+ 'value': u'<source />',
+ 'xtype': 'textarea'}
+
+TextField
+.........
+
+ >>> textWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['textField'], request),
+ ... IFieldWidget)
+ >>> textWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(textWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Text',
+ 'id': 'textField',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'textField',
+ 'value': u'Some\n Text.',
+ 'xtype': 'textarea'}
+
+TextLineField
.............
- >>> from z3c.form.browser.select import SelectFieldWidget
- >>> from zope.schema import Choice
+ >>> textLineWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['textLineField'], request),
+ ... IFieldWidget)
+ >>> textLineWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(textLineWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Text Line',
+ 'id': 'textLineField',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'textLineField',
+ 'value': u'Some Text line.',
+ 'xtype': 'textfield'}
- >>> widget = SelectFieldWidget(
- ... Choice(values=[1,2,3,4]),
- ... TestRequest())
- >>> widget.update()
- >>> widget.label = u'Widget Label'
- >>> widget.id = 'widget-id'
- >>> widget.name = 'widget.name'
- >>> widget.value = 'widget value'
+TimeField
+.........
- >>> pprint(interfaces.IExtJSComponent(widget).getConfig())
- {'editable': False,
- 'fieldLabel': u'Widget Label',
- 'hiddenName': 'widget.name:list',
- 'id': 'widget-id',
- 'name': 'widget.name',
- 'store': [('1', '1'), ('2', '2'), ('3', '3'), ('4', '4')],
- 'triggerAction': 'all',
- 'value': 'widget value',
- 'xtype': 'combo'}
+ >>> timeWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['timeField'], request),
+ ... IFieldWidget)
+ >>> timeWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(timeWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Time',
+ 'id': 'timeField',
+ 'itemCls': 'required',
+ 'name': 'timeField',
+ 'value': u'12:00',
+ 'xtype': 'timefield'}
-Radio Widget
-............
+TimedeltaField
+..............
- >>> from z3c.form.browser.radio import RadioFieldWidget
- >>> widget = RadioFieldWidget(
- ... Choice(values=[1, 2, 3]),
- ... TestRequest())
- >>> widget.update()
- >>> widget.label = u'Widget Label'
- >>> widget.id = 'widget-id'
- >>> widget.name = 'widget.name'
- >>> widget.value = 'widget value'
+Timedelta field has no specific widget. It use the textfield widget
- >>> pprint(interfaces.IExtJSComponent(widget).getConfig())
- {'fieldLabel': u'Widget Label',
- 'id': 'widget-id',
- 'items': [{'boxLabel': '1',
- 'checked': False,
- 'id': 'widget-id-0',
- 'inputValue': '1',
- 'name': 'widget.name'},
- {'boxLabel': '2',
- 'checked': False,
- 'id': 'widget-id-1',
- 'inputValue': '2',
- 'name': 'widget.name'},
- {'boxLabel': '3',
- 'checked': False,
- 'id': 'widget-id-2',
- 'inputValue': '3',
- 'name': 'widget.name'}],
- 'xtype': 'radiogroup'}
+ >>> timedeltaWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['timedeltaField'], request),
+ ... IFieldWidget)
+ >>> timedeltaWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(timedeltaWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'Time Delta',
+ 'id': 'timedeltaField',
+ 'itemCls': 'required',
+ 'name': 'timedeltaField',
+ 'value': u'3 days, 0:00:00',
+ 'xtype': 'textfield'}
-An edge case is a radio widget that has no values to select. ExtJS
-requires there to be an items attribute that is a non empty list. To
-get a similar effect, we just add one hidden item to the items list.
+TupleField
+..........
- >>> widget = RadioFieldWidget(
- ... Choice(values=[]),
- ... TestRequest())
- >>> widget.update()
- >>> widget.label = u'Widget Label'
- >>> widget.id = 'widget-id'
- >>> widget.name = 'widget.name'
- >>> widget.value = 'widget value'
+TODO
- >>> pprint(interfaces.IExtJSComponent(widget).getConfig())
- {'fieldLabel': u'Widget Label',
- 'id': 'widget-id',
- 'items': [{'hidden': True}],
- 'xtype': 'radiogroup'}
+UriField
+........
+ >>> uriWidget = zope.component.getMultiAdapter(
+ ... (IAllFields['uriField'], request),
+ ... IFieldWidget)
+ >>> uriWidget.update()
+ >>> pprint(interfaces.IExtJSComponent(uriWidget).getConfig())
+ {'allowBlank': False,
+ 'fieldLabel': u'URI',
+ 'id': 'uriField',
+ 'itemCls': 'required',
+ 'minLength': 0,
+ 'name': 'uriField',
+ 'value': u'http://zope.org',
+ 'xtype': 'textfield'}
+
+
Form Panels
-----------
@@ -184,63 +545,60 @@
>>> class IPerson(zope.interface.Interface):
...
- ... id = zope.schema.TextLine(
- ... title=u'ID',
- ... readonly=True,
- ... required=True)
+ ... id = zope.schema.TextLine(
+ ... title=u'ID',
+ ... readonly=True,
+ ... required=True)
...
- ... isCool = zope.schema.Bool(
- ... title=u'Are you Cool?',
- ... required=True)
+ ... isCool = zope.schema.Bool(
+ ... title=u'Are you Cool?',
+ ... required=True)
...
- ... name = zope.schema.TextLine(
- ... title=u'Name',
- ... required=True)
+ ... name = zope.schema.TextLine(
+ ... title=u'Name',
+ ... required=True)
...
- ... gender = zope.schema.Choice(
- ... title=u'Gender',
- ... values=('male', 'female'),
- ... required=False)
+ ... gender = zope.schema.Choice(
+ ... title=u'Gender',
+ ... values=('male', 'female'),
+ ... required=False)
...
- ... age = zope.schema.Int(
- ... title=u'Age',
- ... description=u"The person's age.",
- ... min=0,
- ... default=20,
- ... required=False)
+ ... age = zope.schema.Int(
+ ... title=u'Age',
+ ... description=u"The person's age.",
+ ... min=0,
+ ... default=20,
+ ... required=False)
...
- ... passwd = zope.schema.Password(
- ... title=u'Password',
- ... required=True)
+ ... passwd = zope.schema.Password(
+ ... title=u'Password',
+ ... required=True)
...
- ... birthDay = zope.schema.Date(
- ... title=u'Birthday')
+ ... birthDay = zope.schema.Date(
+ ... title=u'Birthday')
...
- ... isNice = zope.schema.Bool(
- ... title=u'Are you Nice?',
- ... required=True)
+ ... isNice = zope.schema.Bool(
+ ... title=u'Are you Nice?',
+ ... required=True)
...
>>> from z3c.form.browser.checkbox import SingleCheckBoxFieldWidget
- >>> from z3c.form.browser.password import PasswordFieldWidget
>>> from z3c.form.interfaces import HIDDEN_MODE
- >>> from z3c.formext.widget import ExtJSDateFieldWidget
>>> class ContactForm(form.Form):
- ... label = u'My Contact Form'
- ... ignoreContext = True
- ... fields = field.Fields(IPerson)
- ... fields['isCool'].widgetFactory = SingleCheckBoxFieldWidget
- ... fields['passwd'].widgetFactory = PasswordFieldWidget
- ... fields['birthDay'].widgetFactory = ExtJSDateFieldWidget
- ... buttons = button.Buttons(button.Button(__name__='save', title=u'Save'))
- ... renderTo = 'my-dom-id'
- ... def updateWidgets(self):
- ... super(ContactForm, self).updateWidgets()
- ... self.widgets['id'].mode = HIDDEN_MODE
+ ... label = u'My Contact Form'
+ ... ignoreContext = True
+ ... fields = field.Fields(IPerson)
+ ... fields['isCool'].widgetFactory = SingleCheckBoxFieldWidget
+ ... buttons = button.Buttons(button.Button(__name__='save', title=u'Save'))
+ ... renderTo = 'my-dom-id'
+ ... def updateWidgets(self):
+ ... super(ContactForm, self).updateWidgets()
+ ... self.widgets['id'].mode = HIDDEN_MODE
>>> myForm = ContactForm('context', TestRequest())
>>> formPanel = interfaces.IExtJSComponent(myForm)
+ >>> myForm.update()
>>> config = formPanel.getConfig()
Now we can look more closely at what we actually get
@@ -257,9 +615,12 @@
Here is a simple text widget
>>> pprint(config['items'][0])
- {'fieldLabel': u'ID',
+ {'allowBlank': False,
+ 'fieldLabel': u'ID',
'hidden': True,
'id': 'form-widgets-id',
+ 'itemCls': 'required',
+ 'minLength': 0,
'name': 'form.widgets.id',
'value': u'',
'xtype': 'textfield'}
@@ -270,68 +631,37 @@
{'checked': False,
'fieldLabel': u'Are you Cool?',
'id': 'form-widgets-isCool',
+ 'itemCls': 'required',
'name': 'form.widgets.isCool',
'xtype': 'checkbox'}
Here is another simple text widget
>>> pprint(config['items'][2])
- {'fieldLabel': u'Name',
+ {'allowBlank': False,
+ 'fieldLabel': u'Name',
'id': 'form-widgets-name',
+ 'itemCls': 'required',
+ 'minLength': 0,
'name': 'form.widgets.name',
'value': u'',
'xtype': 'textfield'}
Here is a select widget
- >>> pprint(config['items'][3])
- {'editable': False,
- 'fieldLabel': u'Gender',
- 'hiddenName': 'form.widgets.gender:list',
- 'id': 'form-widgets-gender',
- 'name': 'form.widgets.gender',
- 'store': [('--NOVALUE--', u'no value'),
- ('male', 'male'),
- ('female', 'female')],
- 'triggerAction': 'all',
- 'value': (),
- 'xtype': 'combo'}
+ >>> pprint(config['items'][3])
+ {'editable': False,
+ 'fieldLabel': u'Gender',
+ 'hiddenName': 'form.widgets.gender:list',
+ 'id': 'form-widgets-gender',
+ 'name': 'form.widgets.gender',
+ 'store': [('--NOVALUE--', u'no value'),
+ ('male', 'male'),
+ ('female', 'female')],
+ 'triggerAction': 'all',
+ 'value': (),
+ 'xtype': 'combo'}
- >>> pprint(config['buttons'])
- [{'id': 'form-buttons-save',
- 'name': 'form.buttons.save',
- 'text': u'Save',
- 'title': u'Save',
- 'xtype': 'button'}]
-
-Here is an integer widget
-
- >>> pprint(config['items'][4])
- {'fieldLabel': u'Age',
- 'id': 'form-widgets-age',
- 'name': 'form.widgets.age',
- 'value': u'20',
- 'xtype': 'textfield'}
-
-Here is a password widget
-
- >>> pprint(config['items'][5])
- {'fieldLabel': u'Password',
- 'id': 'form-widgets-passwd',
- 'inputType': 'password',
- 'name': 'form.widgets.passwd',
- 'value': u'',
- 'xtype': 'textfield'}
-
-Here is a date widget
-
- >>> pprint(config['items'][6])
- {'fieldLabel': u'Birthday',
- 'id': 'form-widgets-birthDay',
- 'name': 'form.widgets.birthDay',
- 'value': u'',
- 'xtype': 'datefield'}
-
Here is a radio group
>>> pprint(config['items'][7])
@@ -349,8 +679,9 @@
'name': 'form.widgets.isNice'}],
'xtype': 'radiogroup'}
+
Helper functions
-----------------
+-----------------
It is sometimes the case that we want to provide information about an
extjs component in a format that doesn't quite fit what extjs wants to
@@ -366,7 +697,7 @@
For example, we can get the set of buttons in either a dictionary
based format (easy for rearraging) or a list format (the way extjs
likes it).
-
+ >>> from z3c.formext import component
>>> pprint(component.getButtonsConfig(myForm))
{'save': {'id': 'form-buttons-save',
'name': 'form.buttons.save',
@@ -388,28 +719,32 @@
>>> pprint(component.getWidgetsConfig(myForm)['isNice'])
{'fieldLabel': u'Are you Nice?',
- 'id': 'form-widgets-isNice',
- 'items': [{'boxLabel': u'yes',
- 'checked': False,
- 'id': 'form-widgets-isNice-0',
- 'inputValue': 'true',
- 'name': 'form.widgets.isNice'},
- {'boxLabel': u'no',
- 'checked': False,
- 'id': 'form-widgets-isNice-1',
- 'inputValue': 'false',
- 'name': 'form.widgets.isNice'}],
- 'xtype': 'radiogroup'}
+ 'id': 'form-widgets-isNice',
+ 'items': [{'boxLabel': u'yes',
+ 'checked': False,
+ 'id': 'form-widgets-isNice-0',
+ 'inputValue': 'true',
+ 'name': 'form.widgets.isNice'},
+ {'boxLabel': u'no',
+ 'checked': False,
+ 'id': 'form-widgets-isNice-1',
+ 'inputValue': 'false',
+ 'name': 'form.widgets.isNice'}],
+ 'xtype': 'radiogroup'}
>>> pprint(component.getWidgetsConfig(myForm, asDict=False)[0])
- {'fieldLabel': u'ID',
+ {'allowBlank': False,
+ 'fieldLabel': u'ID',
'hidden': True,
'id': 'form-widgets-id',
+ 'itemCls': 'required',
+ 'minLength': 0,
'name': 'form.widgets.id',
'value': u'',
'xtype': 'textfield'}
+
Custom Widget Component Factories
---------------------------------
@@ -425,14 +760,17 @@
... self.widgets['id'].componentFactory = MyComponent
>>> myForm = ContactForm('context', TestRequest())
+ >>> myForm.update()
>>> formPanel = interfaces.IExtJSComponent(myForm)
>>> config = formPanel.getConfig()
>>> pprint(config['items'][0])
- {'disabled': True,
+ {'allowBlank': False,
+ 'disabled': True,
'fieldLabel': u'ID',
'id': 'form-widgets-id',
+ 'itemCls': 'required',
+ 'minLength': 0,
'name': 'form.widgets.id',
'value': u'',
'xtype': 'my-component'}
-
Added: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.zcml
===================================================================
--- z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.zcml (rev 0)
+++ z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.zcml 2009-02-26 17:26:13 UTC (rev 97328)
@@ -0,0 +1,167 @@
+<?xml version="1.0"?>
+<configure
+ xmlns="http://namespaces.zope.org/zope"
+ xmlns:z3c="http://namespaces.zope.org/z3c"
+ i18n_domain="z3c.formext">
+
+ <adapter
+ factory=".component.FormPanel"
+ />
+ <adapter
+ factory=".component.ExtFormPanel"
+ />
+
+ <!-- Adapt TextWidget -->
+ <adapter
+ factory=".component.TextField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.IBytesLine"
+ />
+ <adapter
+ factory=".component.TextField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.IASCIILine"
+ />
+ <adapter
+ factory=".component.TextField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.ITextLine"
+ />
+ <adapter
+ factory=".component.TextField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.IId"
+ />
+
+ <adapter
+ factory=".component.TextField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.IDatetime"
+ />
+
+ <adapter
+ factory=".component.TextField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.ITimedelta"
+ />
+
+ <adapter
+ factory=".component.NumberField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.IInt"
+ />
+
+ <adapter
+ factory=".component.NumberField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.IFloat"
+ />
+
+ <adapter
+ factory=".component.NumberField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.IDecimal"
+ />
+
+ <adapter
+ factory=".component.DateField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.IDate"
+ />
+
+ <adapter
+ factory=".component.TimeField"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.ITime"
+ />
+
+ <adapter
+ factory=".component.Password"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextWidget
+ zope.schema.interfaces.IPassword"
+ />
+
+ <!-- Adapt TextAreaWidget -->
+ <adapter
+ factory=".component.TextArea"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextAreaWidget
+ zope.schema.interfaces.IText"
+ />
+
+ <adapter
+ factory=".component.TextArea"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.ITextAreaWidget
+ zope.schema.interfaces.IASCII"
+ />
+
+ <!-- Radio Widget -->
+ <adapter
+ factory=".component.RadioGroup"
+ for="*
+ z3c.form.interfaces.IFormLayer
+ z3c.form.interfaces.IForm
+ z3c.form.interfaces.IRadioWidget
+ zope.schema.interfaces.IBool"
+ />
+ <!-- other widgets -->
+ <adapter
+ factory=".component.DateWidget"
+ />
+ <adapter
+ factory=".component.ComboBox"
+ />
+ <adapter
+ factory=".component.CheckBox"
+ />
+ <adapter
+ factory=".component.Button"
+ />
+ <adapter
+ factory=".component.ClientButton"
+ />
+
+
+</configure>
+
Property changes on: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/component.zcml
___________________________________________________________________
Added: svn:keywords
+ Date Author Id Revision
Modified: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/configure.zcml
===================================================================
--- z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/configure.zcml 2009-02-26 17:23:16 UTC (rev 97327)
+++ z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/configure.zcml 2009-02-26 17:26:13 UTC (rev 97328)
@@ -24,36 +24,7 @@
/>
<!-- ExtJS Component adapters -->
- <adapter
- factory=".component.FormPanel"
- />
- <adapter
- factory=".component.ExtFormPanel"
- />
- <adapter
- factory=".component.TextField"
- />
- <adapter
- factory=".component.TextArea"
- />
- <adapter
- factory=".component.DateField"
- />
- <adapter
- factory=".component.ComboBox"
- />
- <adapter
- factory=".component.CheckBox"
- />
- <adapter
- factory=".component.RadioGroup"
- />
- <adapter
- factory=".component.Button"
- />
- <adapter
- factory=".component.ClientButton"
- />
+ <include file="component.zcml"/>
<adapter
factory=".form.ClientButtonAction"
Modified: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/interfaces.py
===================================================================
--- z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/interfaces.py 2009-02-26 17:23:16 UTC (rev 97327)
+++ z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/interfaces.py 2009-02-26 17:26:13 UTC (rev 97328)
@@ -23,6 +23,8 @@
from z3c.form.interfaces import ITextWidget
from z3c.form.interfaces import ISingleCheckBoxWidget
from z3c.form.interfaces import IForm
+from z3c.form.interfaces import IGroup
+from z3c.form.interfaces import IGroupForm
from z3c.form.interfaces import IButton
from z3c.form.interfaces import IButtonAction
from z3c.form.interfaces import ISelectionManager
@@ -91,6 +93,20 @@
"""A Selection Manager for JavaScript Properties"""
+class IExtJSGroup(IGroup):
+ """The EXTJS translation of a group of fiels/widgets within a form
+
+ see z3c.form.interfaces.IGroup
+ """
+
+
+class IExtJSGroupForm(IGroupForm):
+ """An extjs form that supports groups
+
+ see z3c.form.interfaces.IGroupForm
+ """
+
+
class IExtJSForm(IAJAXRequestHandler, IForm):
jsonResponse = zope.schema.Field(
Modified: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/resources/form-script.js
===================================================================
--- z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/resources/form-script.js 2009-02-26 17:23:16 UTC (rev 97327)
+++ z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/resources/form-script.js 2009-02-26 17:26:13 UTC (rev 97328)
@@ -9,4 +9,4 @@
} else if (config.renderTo){
new z3c.formext.form.Z3CFormPanel(config);
}
- });
\ No newline at end of file
+ });
Modified: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/resources/z3c.formext.loader.js
===================================================================
--- z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/resources/z3c.formext.loader.js 2009-02-26 17:23:16 UTC (rev 97327)
+++ z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/resources/z3c.formext.loader.js 2009-02-26 17:26:13 UTC (rev 97328)
@@ -133,4 +133,4 @@
ScriptManager.loadQueue = ScriptManager.prototype.loadQueue;
ScriptManager.registeredPackages = ScriptManager.prototype.registeredPackages;
ScriptManager.srcScript = ScriptManager.prototype.srcScript;
-ScriptManager.nextQueueItem=ScriptManager.prototype.nextQueueItem();
\ No newline at end of file
+ScriptManager.nextQueueItem=ScriptManager.prototype.nextQueueItem();
Modified: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/testing.py
===================================================================
--- z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/testing.py 2009-02-26 17:23:16 UTC (rev 97327)
+++ z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/testing.py 2009-02-26 17:26:13 UTC (rev 97328)
@@ -17,30 +17,100 @@
"""
import zope.component
import zope.interface
+import zope.schema.interfaces
from zope.traversing.testing import setUp as setupTraversing
from zope.traversing.interfaces import IContainmentRoot
import z3c.form.testing
from z3c.form.interfaces import IButtonAction
+from z3c.form.interfaces import ITextWidget
+from z3c.form.interfaces import ITextAreaWidget
+from z3c.form.interfaces import ISelectWidget
+from z3c.form.interfaces import ISingleCheckBoxWidget
+from z3c.form.interfaces import IRadioWidget
+
from z3c.form.testing import setupFormDefaults
-from z3c.formext import component, form, converter
+from z3c.formext import component, form, converter, interfaces
TestRequest = z3c.form.testing.TestRequest
+
def setupExtJSComponents():
- zope.component.provideAdapter(component.TextField)
- zope.component.provideAdapter(component.TextArea)
- zope.component.provideAdapter(component.DateField)
+ zope.component.provideAdapter(component.SimpleFiedWidgetFactory)
+ #TextWidget
+ # TextField
+ zope.component.provideAdapter(component.TextField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.IBytesLine),
+ interfaces.IExtJSComponent)
+ zope.component.provideAdapter(component.TextField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.IASCIILine),
+ interfaces.IExtJSComponent)
+ zope.component.provideAdapter(component.TextField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.ITextLine),
+ interfaces.IExtJSComponent)
+ zope.component.provideAdapter(component.TextField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.IId),
+ interfaces.IExtJSComponent)
+ zope.component.provideAdapter(component.TextField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.IDatetime),
+ interfaces.IExtJSComponent)
+ zope.component.provideAdapter(component.TextField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.ITimedelta),
+ interfaces.IExtJSComponent)
+ # DateField
+ zope.component.provideAdapter(component.DateField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.IDate),
+ interfaces.IExtJSComponent)
+ # TimeField
+ zope.component.provideAdapter(component.TimeField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.ITime),
+ interfaces.IExtJSComponent)
+ # NumberField
+ zope.component.provideAdapter(component.NumberField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.IInt),
+ interfaces.IExtJSComponent)
+ zope.component.provideAdapter(component.NumberField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.IFloat),
+ interfaces.IExtJSComponent)
+ zope.component.provideAdapter(component.NumberField,
+ (None, None, None, ITextWidget, zope.schema.interfaces.IDecimal),
+ interfaces.IExtJSComponent)
+ # PasswordField
+ zope.component.provideAdapter(component.Password,
+ (None, None, None, ITextWidget,
+ zope.schema.interfaces.IPassword),
+ interfaces.IExtJSComponent)
+ #TextAreaWidget
+ zope.component.provideAdapter(component.TextArea,
+ (None, None, None, ITextAreaWidget, zope.schema.interfaces.IText),
+ interfaces.IExtJSComponent)
+ zope.component.provideAdapter(component.TextArea,
+ (None, None, None, ITextAreaWidget, zope.schema.interfaces.IASCII),
+ interfaces.IExtJSComponent)
+ #RadioWidget
+ zope.component.provideAdapter(component.RadioGroup,
+ (None, None, None, IRadioWidget, zope.schema.interfaces.IBool),
+ interfaces.IExtJSComponent)
+ #other widgets
+ zope.component.provideAdapter(component.DateWidget,
+ (None, None, None,
+ interfaces.IExtJSDateWidget, zope.schema.interfaces.IDate),
+ interfaces.IExtJSComponent)
+ zope.component.provideAdapter(component.ComboBox,
+ (None, None, None, ISelectWidget, zope.schema.interfaces.IChoice),
+ interfaces.IExtJSComponent)
+ zope.component.provideAdapter(component.CheckBox,
+ (None, None, None,
+ ISingleCheckBoxWidget, zope.schema.interfaces.IField),
+ interfaces.IExtJSComponent)
zope.component.provideAdapter(component.FormPanel)
zope.component.provideAdapter(component.ExtFormPanel)
- zope.component.provideAdapter(component.ComboBox)
- zope.component.provideAdapter(component.CheckBox)
- zope.component.provideAdapter(component.RadioGroup)
zope.component.provideAdapter(component.Button)
zope.component.provideAdapter(component.ClientButton)
zope.component.provideAdapter(form.ClientButtonAction,
provides=IButtonAction)
+
def setupFormExt():
setupExtJSComponents()
setupFormDefaults()
@@ -53,6 +123,7 @@
zope.interface.implements(IContainmentRoot)
__name__ = ''
+
class TestingForm(object):
__name__ = 'index.html'
Added: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/tests/interfaces.py
===================================================================
--- z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/tests/interfaces.py (rev 0)
+++ z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/tests/interfaces.py 2009-02-26 17:26:13 UTC (rev 97328)
@@ -0,0 +1,204 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Foundation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""z3c.form Test Module interfaces
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+import datetime
+import decimal
+import zope.interface
+import zope.schema
+from zope.schema import vocabulary
+
+vocab = vocabulary.SimpleVocabulary([
+ vocabulary.SimpleVocabulary.createTerm(1, '1', u'One'),
+ vocabulary.SimpleVocabulary.createTerm(2, '2', u'Two'),
+ vocabulary.SimpleVocabulary.createTerm(3, '3', u'Three'),
+ vocabulary.SimpleVocabulary.createTerm(4, '4', u'Four'),
+ vocabulary.SimpleVocabulary.createTerm(5, '5', u'Five'),
+ ])
+
+class IObjectSchema(zope.interface.Interface):
+
+ field1 = zope.schema.TextLine(
+ title=u'Field 1')
+
+ field2 = zope.schema.Int(
+ title=u'Field 2')
+
+
+class IAllFields(zope.interface.Interface):
+ """An interface containing all possible fields."""
+
+ asciiField = zope.schema.ASCII(
+ title=u'ASCII',
+ description=u'This is an ASCII field.',
+ default='This is\n ASCII.')
+
+ asciiLineField = zope.schema.ASCIILine(
+ title=u'ASCII Line',
+ description=u'This is an ASCII-Line field.',
+ default='An ASCII line.')
+
+ boolField = zope.schema.Bool(
+ title=u'Boolean',
+ description=u'This is a Bool field.',
+ default=True)
+
+ checkboxBoolField = zope.schema.Bool(
+ title=u'Boolean (Checkbox)',
+ description=u'This is a Bool field displayed suing a checkbox.',
+ default=True)
+
+ bytesField = zope.schema.Bytes(
+ title=u'Bytes',
+ description=u'This is a Bytes field.',
+ default='\10\45\n\32',
+ required=False)
+
+ bytesLineField = zope.schema.BytesLine(
+ title=u'Bytes Line',
+ description=u'This is a bytes line field.',
+ default='A Bytes line.')
+
+ choiceField = zope.schema.Choice(
+ title=u'Choice',
+ description=u'This is a choice field.',
+ default=3,
+ vocabulary=vocab)
+
+ optionalChoiceField = zope.schema.Choice(
+ title=u'Choice (Not Required)',
+ description=u'This is a non-required choice field.',
+ vocabulary=vocab,
+ required=False)
+
+ promptChoiceField = zope.schema.Choice(
+ title=u'Choice (Explicit Prompt)',
+ description=u'This is a choice field with an explicit prompt.',
+ vocabulary=vocab,
+ required=False)
+
+ dateField = zope.schema.Date(
+ title=u'Date',
+ description=u'This is a Date field.',
+ default=datetime.date(2007, 4, 1))
+
+ datetimeField = zope.schema.Datetime(
+ title=u'Date/Time',
+ description=u'This is a Datetime field.',
+ default=datetime.datetime(2007, 4, 1, 12))
+
+ decimalField = zope.schema.Decimal(
+ title=u'Decimal',
+ description=u'This is a Decimal field.',
+ default=decimal.Decimal('12.87'))
+
+ dictField = zope.schema.Dict(
+ title=u'Dictionary',
+ description=u'This is a Dictionary field.',
+ key_type=zope.schema.TextLine(),
+ value_type=choiceField,
+ default={u'a': 1, u'c': 3})
+
+ dottedNameField = zope.schema.DottedName(
+ title=u'Dotted Name',
+ description=u'This is a DottedName field.',
+ default='z3c.form')
+
+ floatField = zope.schema.Float(
+ title=u'Float',
+ description=u'This is a Float field.',
+ default=12.8)
+
+ frozenSetField = zope.schema.FrozenSet(
+ title=u'Frozen Set',
+ description=u'This is a FrozenSet field.',
+ value_type=choiceField,
+ default=frozenset([1, 3]), )
+
+ idField = zope.schema.Id(
+ title=u'Id',
+ description=u'This is a Id field.',
+ default='z3c.form')
+
+ intField = zope.schema.Int(
+ title=u'Integer',
+ description=u'This is a Int field.',
+ default=12345)
+
+ listField = zope.schema.List(
+ title=u'List',
+ description=u'This is a List field.',
+ value_type=choiceField,
+ default=[1, 3])
+
+ objectField = zope.schema.Object(
+ title=u'Object',
+ description=u'This is an Object field.',
+ schema=IObjectSchema)
+
+ passwordField = zope.schema.Password(
+ title=u'Password',
+ description=u'This is a Password field.',
+ default=u'mypwd',
+ required=False)
+
+ setField = zope.schema.Set(
+ title=u'Set',
+ description=u'This is a Set field.',
+ value_type=choiceField,
+ default=set([1, 3]), )
+
+ sourceTextField = zope.schema.SourceText(
+ title=u'Source Text',
+ description=u'This is a SourceText field.',
+ default=u'<source />')
+
+ textField = zope.schema.Text(
+ title=u'Text',
+ description=u'This is a Text field.',
+ default=u'Some\n Text.')
+
+ textLineField = zope.schema.TextLine(
+ title=u'Text Line',
+ description=u'This is a TextLine field.',
+ default=u'Some Text line.')
+
+ timeField = zope.schema.Time(
+ title=u'Time',
+ description=u'This is a Time field.',
+ default=datetime.time(12, 0))
+
+ timedeltaField = zope.schema.Timedelta(
+ title=u'Time Delta',
+ description=u'This is a Timedelta field.',
+ default=datetime.timedelta(days=3))
+
+ tupleField = zope.schema.Tuple(
+ title=u'Tuple',
+ description=u'This is a Tuple field.',
+ value_type=choiceField,
+ default=(1, 3))
+
+ uriField = zope.schema.URI(
+ title=u'URI',
+ description=u'This is a URI field.',
+ default='http://zope.org')
+
+ hiddenField = zope.schema.TextLine(
+ title=u'Hidden Text Line',
+ description=u'This is a hidden TextLine field.',
+ default=u'Some Hidden Text.')
Property changes on: z3c.formext/branches/sagblmi-morecomponent/src/z3c/formext/tests/interfaces.py
___________________________________________________________________
Added: svn:keywords
+ Date Author Id Revision
More information about the Checkins
mailing list