[ZPT] how to eliminate redundancy in forms??

Mark A. Lilly mlilly@inkwellmedia.net
Mon, 27 May 2002 14:39:09 -0700


Hi,

I have an HTML form for adding tasks. I want to use the same form for
editing existing tasks.

I am attempting to avoid having two INPUT elements --one for adding and one
for editing.

So i have this code:

	<input type="text" name="input_name" id="input_name"
      	tal:condition="exists:task/task_name | nothing"
		tal:attributes="value python:test(task, task.task_name,  'Add Task')" />

The task variable is populated by returning the 0'th instance from a
ZCatalog Collection based on task_id.  If it is an Add (hence there is no
task to find in the Catalog), i return from the getTask() script an empty
list.

The tal:condition checks to see if task/task_name exists.  If it doesn't, i
want to set the value of the input to the words 'Add Task'.

Problem is, this doesn't work.  The task.task_name inside the python test
function fails on the Add, because there is no task instance with a field
called task_name --i get an "AttributeError on task_name". It works when
there is a task returned.

Question: how do i set this up? I want only one <INPUT> which is reused for
adding/editing. Otherwise, i have to duplicate tons of code.

Suggestions?

Thanks,
mark