[Zope] Dynamically generating fielsd in a form

Dieter Maurer dieter@handshake.de
Wed, 15 Jan 2003 23:48:12 +0100


aborel wrote at 2003-1-15 11:07 -0400:
 > Some questions on tal:repeat.
 > 
 > 1) Generating fields
 > 
 > I have an object called 'process'
 > this object contains a list of steps to follow to perform the process.
 > A step have a type that may be 'unique' or 'repeated'
 > 	For example : an invoice
 > 	CustomerId : Unique step
 > 	ProductId  : Repeated step (number of repetitions undefined)
 > 			ProductId : 1 (sub-step)
 > 			ProductId : 2 (sub-step)
 > 			...
 > 			ProductId : n (sub-step)(repeated until user 					chosees next step)
 > 	NetDue     : Unique step
 > 
 > What i want to do is to generate fields steps by step depending on the
 > type of the step by using tal:repeat to loop over the list of steps and
 > display the rights fields.
 > A 'unique' step will have one submit button : Next Step
 > A 'repeated' step will have to submit buttons : Validate (to fill in a
 > new sub-step) and Next Step.
 > Tal:repeat is useful on 'uniqu'e steps  but when i encounter a
 > 'repeated' step, i can't use it as it's not a sequence and the number of
 > repetitions is undefined.
 > 
 > Any Suggestions will be greatly appreciated.
This is similar to a tree generation.

Have a look at "ZTUtils.Tree" and the corresponding example
(in the ZPT examples).

 > 2) Validating fields
 > 
 > Is it possible to use Python scripts instead of Ecma scripts on core
 > events like onBlur, Onclick and so on ?
No.

You can use Python scripts for validation on the server side
(after the form is submitted).

 > 3) Displaying the fields
 > 
 > Each time a field is filled in, i'd like to display it at the end of a
 > listing without re-redenring all the web page, just the changes
 > (understandable ??? ;-)).
You want to learn about DHTML (Dynamic HTML).
You do this with JavaScript.
 > ...
 > 4) Storing the generated objects
 > 
 > The form template will be called from various place on the site so how
 > do i indicate the exact place to store the generated objects ?
You use the form action like a method of the target object.
If it is a Python Script (this is a good suggestion), then
"context" is the target object. You can create the object
at any place you can reach via "context".


Dieter