[Checkins] SVN: zc.ajax/branches/dev/src/zc/ajax/ Further de-Ext-ified

Jim Fulton jim at zope.com
Wed Apr 1 14:59:30 EDT 2009


Log message for revision 98771:
  Further de-Ext-ified
  

Changed:
  U   zc.ajax/branches/dev/src/zc/ajax/form.txt
  U   zc.ajax/branches/dev/src/zc/ajax/widgets.py
  U   zc.ajax/branches/dev/src/zc/ajax/widgets.txt

-=-
Modified: zc.ajax/branches/dev/src/zc/ajax/form.txt
===================================================================
--- zc.ajax/branches/dev/src/zc/ajax/form.txt	2009-04-01 18:35:01 UTC (rev 98770)
+++ zc.ajax/branches/dev/src/zc/ajax/form.txt	2009-04-01 18:59:29 UTC (rev 98771)
@@ -1,3 +1,4 @@
+
 Form Processing
 ===============
 
@@ -58,32 +59,32 @@
                      u'widgets': [{u'fieldHint': u'Given name.',
                                    u'fieldLabel': u'First name',
                                    u'id': u'ExampleForm.first_name',
-                                   u'itemCls': u'zc-required-field',
                                    u'minLength': 0,
                                    u'name': u'ExampleForm.first_name',
-                                   u'xtype': u'textfield'},
+                                   u'required': True,
+                                   u'widget_constructor': u'zc.ajax.widgets.InputTextLine'},
                                   {u'fieldHint': u'Family name.',
                                    u'fieldLabel': u'Last name',
                                    u'id': u'ExampleForm.last_name',
-                                   u'itemCls': u'zc-required-field',
                                    u'minLength': 0,
                                    u'name': u'ExampleForm.last_name',
-                                   u'xtype': u'textfield'},
+                                   u'required': True,
+                                   u'widget_constructor': u'zc.ajax.widgets.InputTextLine'},
                                   {u'fieldHint': u'',
                                    u'fieldLabel': u'Favorite color',
                                    u'id': u'ExampleForm.favorite_color',
                                    u'minLength': 0,
                                    u'name': u'ExampleForm.favorite_color',
-                                   u'xtype': u'textfield'},
+                                   u'widget_constructor': u'zc.ajax.widgets.InputTextLine'},
                                   {u'allowBlank': False,
                                    u'fieldHint': u'Age in years',
                                    u'fieldLabel': u'Age',
                                    u'field_min': 0,
                                    u'id': u'ExampleForm.age',
-                                   u'itemCls': u'zc-required-field',
                                    u'name': u'ExampleForm.age',
+                                   u'required': True,
                                    u'widget_constructor':
-                                    u'zc.ajax.widgets.InputInt'}]},
+                                   u'zc.ajax.widgets.InputInt'}]},
      u'success': True}
 
 Our application is at: "http://localhost/form.html". The form is
@@ -189,30 +190,30 @@
      'widgets': [{'fieldHint': u'Given name.',
                   'fieldLabel': u'First name',
                   'id': 'ExampleForm.first_name',
-                  'itemCls': 'zc-required-field',
                   'minLength': 0,
                   'name': 'ExampleForm.first_name',
-                  'xtype': 'textfield'},
+                  'required': True,
+                  'widget_constructor': 'zc.ajax.widgets.InputTextLine'},
                  {'fieldHint': u'Family name.',
                   'fieldLabel': u'Last name',
                   'id': 'ExampleForm.last_name',
-                  'itemCls': 'zc-required-field',
                   'minLength': 0,
                   'name': 'ExampleForm.last_name',
-                  'xtype': 'textfield'},
+                  'required': True,
+                  'widget_constructor': 'zc.ajax.widgets.InputTextLine'},
                  {'fieldHint': u'',
                   'fieldLabel': u'Favorite color',
                   'id': 'ExampleForm.favorite_color',
                   'minLength': 0,
                   'name': 'ExampleForm.favorite_color',
-                  'xtype': 'textfield'},
+                  'widget_constructor': 'zc.ajax.widgets.InputTextLine'},
                  {'allowBlank': False,
                   'fieldHint': u'Age in years',
                   'fieldLabel': u'Age',
                   'field_min': 0,
                   'id': 'ExampleForm.age',
-                  'itemCls': 'zc-required-field',
                   'name': 'ExampleForm.age',
+                  'required': True,
                   'widget_constructor': 'zc.ajax.widgets.InputInt'}]}
 
 Note that we had to stamp the request with IAjaxRequest.  This is done
@@ -245,30 +246,30 @@
      'widgets': [{'fieldHint': u'Given name.',
                   'fieldLabel': u'First name',
                   'id': 'sample.ExampleForm.first_name',
-                  'itemCls': 'zc-required-field',
                   'minLength': 0,
                   'name': 'sample.ExampleForm.first_name',
-                  'xtype': 'textfield'},
+                  'required': True,
+                  'widget_constructor': 'zc.ajax.widgets.InputTextLine'},
                  {'fieldHint': u'Family name.',
                   'fieldLabel': u'Last name',
                   'id': 'sample.ExampleForm.last_name',
-                  'itemCls': 'zc-required-field',
                   'minLength': 0,
                   'name': 'sample.ExampleForm.last_name',
-                  'xtype': 'textfield'},
+                  'required': True,
+                  'widget_constructor': 'zc.ajax.widgets.InputTextLine'},
                  {'fieldHint': u'',
                   'fieldLabel': u'Favorite color',
                   'id': 'sample.ExampleForm.favorite_color',
                   'minLength': 0,
                   'name': 'sample.ExampleForm.favorite_color',
-                  'xtype': 'textfield'},
+                  'widget_constructor': 'zc.ajax.widgets.InputTextLine'},
                  {'allowBlank': False,
                   'fieldHint': u'Age in years',
                   'fieldLabel': u'Age',
                   'field_min': 0,
                   'id': 'sample.ExampleForm.age',
-                  'itemCls': 'zc-required-field',
                   'name': 'sample.ExampleForm.age',
+                  'required': True,
                   'widget_constructor': 'zc.ajax.widgets.InputInt'}]}
 
 Note that the action URL now includes "sample/" as a prefix.  Also

Modified: zc.ajax/branches/dev/src/zc/ajax/widgets.py
===================================================================
--- zc.ajax/branches/dev/src/zc/ajax/widgets.py	2009-04-01 18:35:01 UTC (rev 98770)
+++ zc.ajax/branches/dev/src/zc/ajax/widgets.py	2009-04-01 18:59:29 UTC (rev 98771)
@@ -30,9 +30,6 @@
 
     zope.interface.implements(zc.ajax.interfaces.IInputWidget)
 
-    xtype = None
-    widget_constructor = None
-
     def js_config(self, **kw):
         config = dict(
             fieldLabel = self.label,
@@ -41,25 +38,18 @@
             id = self.name,
             **kw)
 
-        if self.xtype:
-            config['xtype'] = self.xtype
-        elif not self.widget_constructor:
-            raise ValueError(
-                'Neither xtype nor widget_constructor are defined.')
+        config['widget_constructor'] = self.widget_constructor
 
-        if self.widget_constructor:
-            config['widget_constructor'] = self.widget_constructor
-        
         if self.required:
-            config['itemCls'] = 'zc-required-field'
+            config['required'] = True
 
         if self._renderedValueSet():
             value = self.formValue(self._data)
             if value is not None:
                 config['value'] = value
-        
-        return config 
 
+        return config
+
     def formValue(self, v):
         if v == self.context.missing_value:
             return None
@@ -67,7 +57,7 @@
 
     def value(self, raw):
         return self._toValue(raw)
-    
+
     def _toValue(self, v):              # for backward compat for a while
         return v
 
@@ -92,18 +82,18 @@
                     self.name, self.label, None)
             else:
                 return self.context.missing_value
-            
+
         value = self.value(raw)
-        
+
         # value must be valid per the field constraints
         try:
             self.context.validate(value)
         except zope.schema.interfaces.ValidationError, v:
             raise zope.app.form.interfaces.WidgetInputError(
                 self.context.__name__, self.label, v)
-            
+
         return value
- 
+
     @zope.cachedescriptors.property.Lazy
     def required(self):
         return self.context.required
@@ -115,11 +105,11 @@
         zc.ajax.interfaces.IAjaxRequest,
         )
 
-    xtype = 'checkbox'
+    widget_constructor = 'zc.ajax.widgets.InputBool'
 
     def hasInput(self):
         return True
-        
+
     def getInputValue(self):
         return self.request.form.get(self.name, '') == 'on'
 
@@ -165,7 +155,7 @@
             [term.token, term.title]
             for term in (terms.getTerm(v) for v in self.source)
             ]
-        
+
         if self.required:
             result['allowBlank'] = False
 
@@ -186,7 +176,7 @@
             zope.app.form.browser.interfaces.ITerms,
             )
         return terms.getValue(v)
-    
+
 class InputChoiceTokenized(InputChoiceIterable):
 
     zope.component.adapts(
@@ -203,7 +193,7 @@
             [term.token, term.title or unicode(term.value)]
             for term in self.source
             ]
-        
+
         if self.required:
             result['allowBlank'] = False
 
@@ -249,7 +239,7 @@
 
         if self.required:
             config['allowBlank'] = False
-        
+
         if self.context.min is not None:
             config['field_min'] = self.context.min
         if self.context.max is not None:
@@ -303,11 +293,11 @@
         zc.ajax.interfaces.IAjaxRequest,
         )
 
-    xtype = 'textfield'
+    widget_constructor = 'zc.ajax.widgets.InputTextLine'
 
     def _is_missing(self, raw):
         return (not raw) and self.required
-    
+
     def js_config(self):
         config = Base.js_config(self)
         if self.context.min_length is not None:
@@ -317,7 +307,7 @@
 
         if self.context.max_length is not None:
             config['maxLength'] = self.context.max_length
-            
+
         return config
 
 class InputText(InputTextLine):
@@ -327,8 +317,8 @@
         zc.ajax.interfaces.IAjaxRequest,
         )
 
-    xtype = 'textarea'
+    widget_constructor = 'zc.ajax.widgets.InputText'
 
 class Hidden(Base):
 
-    xtype = 'hidden'
+    widget_constructor = 'zc.ajax.widgets.Hidden'

Modified: zc.ajax/branches/dev/src/zc/ajax/widgets.txt
===================================================================
--- zc.ajax/branches/dev/src/zc/ajax/widgets.txt	2009-04-01 18:35:01 UTC (rev 98770)
+++ zc.ajax/branches/dev/src/zc/ajax/widgets.txt	2009-04-01 18:59:29 UTC (rev 98771)
@@ -37,7 +37,7 @@
 
   value(v)
       Convert a raw value sent from the client to an application value.
-  
+
   _is_missing(self, v)
       Return a boolean value indicating whether the given raw value is
       equivalent to the user not providing a value.
@@ -67,19 +67,20 @@
     >>> pprint(w.js_config(), width=1)
     Traceback (most recent call last):
     ...
-    ValueError: Neither xtype nor widget_constructor are defined.
+    AttributeError: 'Base' object has no attribute 'widget_constructor'
 
 Oops, let's make this a text widget. Normally we'd do this in a widget
 class. We'll just hack the widget instance. :)
 
-    >>> w.xtype = 'textfield'
+
+    >>> w.widget_constructor = 'zc.ajax.widgets.InputTextLine'
     >>> pprint(w.js_config(), width=1)
     {'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
-     'xtype': 'textfield'}
+     'required': True,
+     'widget_constructor': 'zc.ajax.widgets.InputTextLine'}
 
 We can also (or instead) provide a widget constructor:
 
@@ -88,11 +89,10 @@
     {'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
-     'widget_constructor': 'my.widget.constructor',
-     'xtype': 'textfield'}
-   
+     'required': True,
+     'widget_constructor': 'my.widget.constructor'}
+
 Let's add some data to the request:
 
     >>> request.form['field.f'] = 'xxx'
@@ -136,21 +136,19 @@
     {'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
-     'widget_constructor': 'my.widget.constructor',
-     'xtype': 'textfield'}
+     'required': True,
+     'widget_constructor': 'my.widget.constructor'}
 
     >>> w.setRenderedValue(w.getInputValue())
     >>> pprint(w.js_config(), width=1)
     {'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
+     'required': True,
      'value': u'foo',
-     'widget_constructor': 'my.widget.constructor',
-     'xtype': 'textfield'}
+     'widget_constructor': 'my.widget.constructor'}
 
 The field constraint doesn't get checked on the client, but is checked
 on the server:
@@ -195,9 +193,9 @@
     {'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
-     'xtype': 'checkbox'}
+     'required': True,
+     'widget_constructor': 'zc.ajax.widgets.InputBool'}
 
     >>> w.formValue(None), w.formValue(True), w.formValue(False)
     (None, True, False)
@@ -239,10 +237,10 @@
     {'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'minLength': 0,
      'name': 'field.f',
-     'xtype': 'textfield'}
+     'required': True,
+     'widget_constructor': 'zc.ajax.widgets.InputTextLine'}
 
     >>> w.formValue(None), w.formValue(u'xxx')
     (None, u'xxx')
@@ -272,11 +270,11 @@
      'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'maxLength': 30,
      'minLength': 5,
      'name': 'field.f',
-     'xtype': 'textfield'}
+     'required': True,
+     'widget_constructor': 'zc.ajax.widgets.InputTextLine'}
 
     >>> w.required, w.hasInput(), w.hasValidInput()
     (True, True, False)
@@ -321,10 +319,10 @@
     {'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'minLength': 0,
      'name': 'field.f',
-     'xtype': 'textarea'}
+     'required': True,
+     'widget_constructor': 'zc.ajax.widgets.InputText'}
 
     >>> w.required, w.hasInput(), w.hasValidInput()
     (True, False, False)
@@ -351,11 +349,11 @@
      'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'maxLength': 30,
      'minLength': 5,
      'name': 'field.f',
-     'xtype': 'textarea'}
+     'required': True,
+     'widget_constructor': 'zc.ajax.widgets.InputText'}
 
     >>> w.required, w.hasInput(), w.hasValidInput()
     (True, True, False)
@@ -399,8 +397,8 @@
      'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
+     'required': True,
      'widget_constructor': 'zc.ajax.widgets.InputInt'}
 
 Note that we use a custom widget constructor, which provides
@@ -444,8 +442,8 @@
      'field_max': 9,
      'field_min': 1,
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
+     'required': True,
      'widget_constructor': 'zc.ajax.widgets.InputInt'}
 
     >>> w.required, w.hasInput(), w.hasValidInput()
@@ -482,8 +480,8 @@
      'fieldLabel': u'label',
      'hiddenName': 'field.f.value',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
+     'required': True,
      'values': [['red',
                  u'red'],
                 ['green',
@@ -553,8 +551,8 @@
      'fieldLabel': u'label',
      'hiddenName': 'field.f.value',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
+     'required': True,
      'values': [['0x41',
                  'A'],
                 ['0x42',
@@ -603,8 +601,8 @@
      'fieldLabel': u'Timezone',
      'hiddenName': 'field.tz.value',
      'id': 'field.tz',
-     'itemCls': 'zc-required-field',
      'name': 'field.tz',
+     'required': True,
      'values': [['Africa/Abidjan',
                  u'Africa/Abidjan'],
                 ...],
@@ -641,8 +639,8 @@
      'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
+     'required': True,
      'widget_constructor': 'zc.ajax.widgets.InputDecimal'}
 
 Note that we use a custom widget constructor, which provides
@@ -684,9 +682,9 @@
     {'fieldHint': u'hint',
      'fieldLabel': u'label',
      'id': 'field.f',
-     'itemCls': 'zc-required-field',
      'name': 'field.f',
-     'xtype': 'hidden'}
+     'required': True,
+     'widget_constructor': 'zc.ajax.widgets.Hidden'}
 
     >>> w.formValue(None), w.formValue(u'xxx')
     (None, u'xxx')



More information about the Checkins mailing list