[Zope] using form for add and edit help please.

Tony McDonald tony.mcdonald@ncl.ac.uk
Mon, 27 May 2002 14:11:08 +0100


On 23/5/02 12:11 am, "Mark Lilly" <mark.lilly@conceracorp.com> wrote:

> Hi,
> I am trying to use the same for for adding and editing.  If we are editing a
> record, i want to insert its value. If we are adding, i want to have a blank
> input text element.
> 
> Instead of having two input elements for each form element, i have come up
> with this:
> <td class="add" valign="top">
> <input type="hidden" name="prev_input_name" value="" />
> <input type="text" name="input_name" id="input_name"
> tal:condition="exists:task/task_name | nothing"
> tal:attributes="value python:test(task, 'insert here',  '')"
> />            
> </td>
> 
> Here is the code that fills the task variable:
> <div tal:define="theTaskId request/task_id | string:0; task
> python:root.CT.Scripts.P_Scripts.getTask(theTaskId)">
> 
> If task_id = 0, the python script will return an empty list. Otherwise, it
> will return the 0th instance in the Catalog's collection.
> 
> I can't figure out what to put in place of 'insert here' in the above Input
> element.  
> I tried to use task/task_item but i get a NameError on global name
> 'task_item' is not defined.
> I tried getattr(task, 'task_name') but got an AttributeError on task_name.
> I can't define a variable using task/task_name, because if it's empty, it
> returns an error.
> Any thoughts on how i can pull this off?
> Thanks,
> mark
> 
> 

This is something really neat that we could certainly benefit from.

Have you tried replacing the 'nothing' with some value that you recognise as
empty?

You might also get more help from the ZPT list - people eat sleep and drink
ZPT there.
 
Hth
Tone.
-- 
Dr Tony McDonald,  Assistant Director, FMCC, http://www.fmcc.org.uk/
The Medical School, Newcastle University Tel: +44 191 243 6140
A Zope list for UK HE/FE  http://www.fmcc.org.uk/mailman/listinfo/zope