[Zope] Data type coercion and "records"
Mayers, Philip J
p.mayers@ic.ac.uk
Thu, 18 Jan 2001 12:25:43 -0000
*Now* I remember why I like Zope so much...
I'm using the ":records" to marshall a complex hierarchical form, and I'm a
little worried by this comment:
http://www.zope.org/Members/Zen/howto/FormVariableTypes
Note:
Before creating a second record and adding an attribute, Zope gets the last
record in the list and checks to see if that record has the attribute. If
the first record doesn't have the attribute, it inserts the attribute and
value instead of creating a new record. For example, if the user entered a
name and age for Member #1 and only an email for Member #2, the list will
have only one record. That record will contain the name and age attribute
from Member #1 as well as the email attribute from Member #2.
This isn't a problem for me, *except* <sigh>. I want to be able to tickbox
certain fields to delete them, as well as alter the values in the textboxes
to alter other fields. *BUT*, my HTML manual says that "CHECKBOX name/value
pairs are only submitted to the server if the field is checked"
So, I would expect this:
<dtml-var standard_html_header>
<table>
<dtml-if list><dtml-in list>
<tr>
<td>&dtml-a;</td>
<dtml-if b><td>&dtml-b;</td></dtml-if>
</tr>
</dtml-in></dtml-if>
</table>
<form><table>
<tr>
<td><input type="text" name="list.a:records" value="1a"></td>
<td><input type="checkbox" name="list.b:records" value="1b"></td>
</tr><tr>
<td><input type="text" name="list.a:records" value="2a"></td>
<td><input type="checkbox" name="list.b:records" value="2b"></td>
</tr><tr>
<td><input type="text" name="list.a:records" value="3a"></td>
<td><input type="checkbox" name="list.b:records" value="3b"></td>
</tr><tr>
<td><input type="text" name="list.a:records" value="4a"></td>
<td><input type="checkbox" name="list.b:records" value="4b"></td>
</tr><tr>
</table>
<input type="submit" value="test">
</form>
<dtml-var standard_html_footer>
To read:
1a
2a
3a 4b
4a
If you just ticked the 4th listbox. But it doesn't - it works as I "want" it
to work, i.e. it reads:
1a
2a
3a
4a 4b
Why? I'm glad this does, but as the saying goes, if you don't understand it,
it can bite you when you least expect it. I've tested this under netscape 6
and IE5.0.
I know I can work around it (set the value field of the checkbox to contain
the information it's referring to) but I'm curious as to what's going on. I
note that if you swap the textbox and checkbox around, it does indeed
"break", and the delete is associated with the previous record as you'd
expect.
So - I suspect the behavious of "records" changed at some point? My question
then becomes - does the HTML/HTTP spec guarantee that if I put the
checkboxes *after* the textboxes, and Zope is marshalling the records in a
useful fashion, this will always work on a conforming browser?
Regards,
Phil
+----------------------------------+
| Phil Mayers, Network Support |
| Centre for Computing Services |
| Imperial College |
+----------------------------------+