Author: jmorliaguet
Date: Thu Feb  9 12:02:27 2006
New Revision: 2329

Modified:
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
   
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
Log:

- the form data is generic from the schema def

- added an optional 'initial value' for the fields



Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
     (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/browser.py
     Thu Feb  9 12:02:27 2006
@@ -13,51 +13,53 @@
 # could be obtained from zope3 schema definitions
 schema = {
     'firstname': {
+         'label': u'First name',
          'required': True,
     },
     'lastname': {
+         'label': u'Last name',
          'required': True,
     },
     'email': {
+         'label': u'Email address',
          'required': False,
+         'initial_value': '[EMAIL PROTECTED]',
          'constraint': re.compile("^([0-9a-z_&.+-]+!)*[0-9a-z_&.+-]+"
                                   "@(([0-9a-z]([0-9a-z-]*[0-9a-z])?\.)+"
                                   
"[a-z]{2,3}|([0-9]{1,3}\.){3}[0-9]{1,3})$").match,
     },
 }
 
-# Form data (resides on the client, can be modified by the server)
-# could be generated automatically from the schema definition
-initial_form_data = {
-    'fields': [
-        {'label': u'First name',
-         'name': u'firstname',
-         'value': u'',
-         'status': u'',
-        },
-        {'label': u'Last name',
-         'name': u'lastname',
-         'value': u'',
-         'status': u'',
-        },
-        {'label': u'Email address',
-         'name': u'email',
-         'value': u'',
-         'status': u'',
-        }
-    ]
-}
+form_layout = ['firstname', 'lastname', 'email']
 
 class Views(BrowserView):
 
+    def __init__(self, context, request):
+        self.context = context
+        self.request = request
+
+        self.initial_form_data = self._initializeFormData()
+
+    def _initializeFormData(self):
+        fields = []
+        for name in form_layout:
+            field_def = schema[name]
+            fields.append({
+                'name': name,
+                'label': field_def['label'],
+                'value': field_def.get('initial_value', u''),
+                'status': u'',
+            })
+        return {'fields': fields}
+
     def getFormData(self):
-        data = cache.query('formdata', {}, initial_form_data)
+        data = cache.query('formdata', {}, self.initial_form_data)
         return json.write(data)
 
     def setFormData(self, data):
         data = json.read(data)
 
-        form_data = cache.query('formdata', {}, initial_form_data)
+        form_data = cache.query('formdata', {}, self.initial_form_data)
         fields = form_data['fields'][:]
 
         for field in fields:

Modified: 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
==============================================================================
--- 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
    (original)
+++ 
cpsskins/branches/jmo-perspectives/ui/framework/tests/zope3/functional/forms/cpsskins_form_validation.pt
    Thu Feb  9 12:02:27 2006
@@ -17,7 +17,7 @@
   <style type="text/css">
   form {
     border: 1px solid #ccc;
-    background-color: #f3f3f0;
+    background-color: #f6f3f0;
     padding: 1em;
     font: 1.3em arial, sans-serif;
     width: 500px;
@@ -32,8 +32,19 @@
     padding: 1em;
   }
 
+  input {
+    border: 1px solid #999;
+    background-color: #fff;
+  }
+
+  input:focus {
+    background-color: #ffc;
+  }
+
   button {
     margin: 1em;
+    border: 1px solid #999;
+    background-color: #ddd;
   }
   </style>
 
@@ -111,6 +122,10 @@
 
   <h1>CPSSkins: simple form validation</h1>
 
+  <p>In this example the form data is validated on the server.</p>
+
+  <p>The schema definition for each field is located on the server</p>
+
   <ins class="controller">
   {"id": "form-controller",
    "type": "form"
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to