Dynamically generating fielsd in a form
Hello, 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. 2) Validating fields Is it possible to use Python scripts instead of Ecma scripts on core events like onBlur, Onclick and so on ? 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 ??? ;-)). How this is managed ? 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 ? Thanks Andre
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
Well, it's not a tree. The 'process' object is a model to follow to dynamically generate fields to fill in in a form. When a step model is 'repeated' that means that the form will have to generate a field (a clone of the step model) and then will have to look to the submit button (validate) to generate a new clone, or (Newt Step) to read the next step model. If a step is 'unique', the form will jump to the new step after validation (the next step button). I don't know if my question is clear. If not, i'll reformulate it. (english is not my mother language but french is.) I wanted to avoid learning Javascript as in the past weeks i began to learn Python, Zope, Plone, CSS, HTML and so on? Pfff. I supposed that JS might be necessary but... Where can i find documentation on DHTML ? I suppose context is relative to acquisition so i have to dive into acquisition. What suggestions would you make to a newbie to structure his learning of Zope ? A method to learn. Note that by reading and crossing thousands of pages i begin to have a precise global vision of the system but what i'd like to do is to go back to the beginning and read again with my new knowledge. But what is the beginning and what must be the steps to follow to be on the way of having a deep and structured knowledge before years of experience ;-) And thanks for the job you do for the community Andre Dieter Maurer a écrit:
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
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
D2 wrote at 2003-1-16 13:36 -0400:
Well, it's not a tree. The 'process' object is a model to follow to dynamically generate fields to fill in in a form. I have understood that.
You want to display a dynamic structure in ZPT. You do not know the depth of the structure before hand. Therefore, a fixed nesting of "tal:repeat" will not work. When you *WOULD* display a tree, you would face the same problem. The tree display in the ZPT examples has solved the problem. It may be worth (for you!) to look at this solution. Dieter
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 Well, if i well understood : First case : I know the URL of the place to store (ObjectManager ?) then the URL will be http://...../ObjectManager/FormTemplate And inside my form i will use 'context' wich will be the ObjectManager. Second case : I don't know the URL of the ObjectManager. So whatever the way it is found, it must be in the REQUEST object. I pass the REQUEST to a Python script and then this script will generate a RESPONSE, redirected to the same URL as mentionned in the first case. My form will be generalized and populated by the URL or the REQUEST. Does it make sense ?
D2 wrote at 2003-1-16 15:39 -0400:
First case : I know the URL of the place to store (ObjectManager ?) then the URL will be http://...../ObjectManager/FormTemplate And inside my form i will use 'context' wich will be the ObjectManager. I do not expect that you let your form store the object but the corresponding form action.
But otherwise, this is okay.
Second case : I don't know the URL of the ObjectManager. This is impossible.
When you want to store the object somewhere, you must know where...
So whatever the way it is found, it must be in the REQUEST object. "restrictedTraverse" may help you to locate the object (--> embedded Zope Help System --> Zope Help --> API Reference --> ObjectManagerItem).
I pass the REQUEST to a Python script and then this script will generate a RESPONSE, redirected to the same URL as mentionned in the first case. The same seems a bit strange.
My form will be generalized and populated by the URL or the REQUEST. I still think, its the action and not the form....
Does it make sense ? I do not yet feel confident...
Dieter
Dieter Maurer wrote...
I do not yet feel confident...
So do i ,-) ; my explanation was not clear. Sorry Concerning the TREE. You saw it as a tree because i described it as a tree. But it's not a tree. Despite my bad explanation, you pointed out some points i had to verify. I hope my brain has been cleaned enough to let me reformulate (hoping that i don't bother you) and verify my understanding of some concepts. ZPT is dynamic in that it dynamically generates HTML. HTML is not dynamic by itself so if i want to have a dynamic HTML page, i must use CSS or Javascript. With ZPT i can insert/call Javascripts or references to Javascripts in my generated HTML so the HTML will behave dynamically by itself. Form/Action/Response Process (I'm using Plone.) 1) CALL a method on an Object LOCATE the object by the action associated to the object in portal_actions, or, by using restrictedTraverse to generate a selection form, wich will display a list of objects on wich the method may be called, and wich action will generate an URL of the form : http://.../Located_Object/Method_to_Apply. 2) SUBMIT the form to an ACTION wich will validate the form and return a status managed by plone's form_properties and navigation_properties. My need I have to create a document wich must contain n lines - the number is not important - of different TYPES. There may be unique or multiple lines of a certain type in the document. The repetition is defined in a 'model'. Lines of the same type are grouped and the TYPE order is defined in the 'model' The model will contain a 'linestack' property wich will be an ordered tuple of dictionaries. Each dictionary will contain the following keys: LINE_TYPE OCCURENCE other keys to populate the generated line The model will contain an empty 'lines' property wich will be used in the generated object and wich will contain the generated lines completed by the user. i.e the model 'invoice' will contain a linestack with ({LINE_TYPE:CUSTOMER_ID, OCCURENCE:UNIQUE}, {LINE_TYPE:PRODUCTS, OCCURENCE:MULTIPLE}, {LINE_TYPE:TAXES, OCCURENCE:MULTIPLE}) and so on. My solution Select the model to use via a form the action form will clone the model and will redirect to an URL calling a method on the cloned object. The method will loop over the 'linestack', populate the fields of the line, generate fields for user input, display only a 'NextStep' button on UNIQUE lines and a 'NextLine' and a 'NextStep' buttons on MULTIPLE lines. The action will append the new generated line to the 'lines' property. On 'NextLine' the action will re-call the method on the object. On 'NextStep', the action will suppress the first dictionary of 'linestack' and will re-call the method on the object until 'linestack' will be empty. Then the process will be completed. Andre Dieter Maurer a écrit:
D2 wrote at 2003-1-16 15:39 -0400:
First case : I know the URL of the place to store (ObjectManager ?) then the URL will be http://...../ObjectManager/FormTemplate And inside my form i will use 'context' wich will be the ObjectManager. I do not expect that you let your form store the object but the corresponding form action.
That's right and the action will be a Python script
But otherwise, this is okay.
Second case : I don't know the URL of the ObjectManager. This is impossible.
When you want to store the object somewhere, you must know where...
So whatever the way it is found, it must be in the REQUEST object. "restrictedTraverse" may help you to locate the object (--> embedded Zope Help System --> Zope Help --> API Reference --> ObjectManagerItem).
I pass the REQUEST to a Python script and then this script will generate a RESPONSE, redirected to the same URL as mentionned in the first case. The same seems a bit strange.
My form will be generalized and populated by the URL or the REQUEST. I still think, its the action and not the form....
Does it make sense ? I do not yet feel confident...
Dieter
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Andre PZP Enthusiast
participants (3)
-
aborel -
D2 -
Dieter Maurer