[Zope] eliminating redundancy in forms, one solution

Mark A. Lilly mlilly@inkwellmedia.net
Mon, 17 Jun 2002 05:54:02 -0700


Hi,
I have been striving for weeks to be able to use the same HTML form for both
editing existing objects, and entering new objects.  What i did not want to
do was to have two <INPUT> elements like this:

<input type="text" name="input_name"
	tal:condition="exists:task/task_name"
	tal:attributes="value task/task_name" />

<input type="text" name="input_name"
	tal:condition="not:exists:task/task_name"
	tal:attributes="value string:Enter Name Here" />

To get around this, i am using the python script that returns the desired
task instance from the ZCatalog.  If the task_id parameter to the python
script is 0 (or one could check to see if any ZCatalog brain instances are
returned from the ZCatalog), i create a small dictionary to act as the
transient object to hold whatever default data i need, like this:

if (task_id == '0'):
  task = {'task_name' : 'Enter Name Here'}
  return task
else:
  return context.tasks.Catalog({'id' : task_id})[0]

Now, my <input> tag simply looks like this:

<input type="text" name="input_name"
      tal:attributes="value task/task_name"  />

Just wanted to put this out for the record, as i know some folks have asked
me if i had found a solution yet.

Cheers,
mark