Jorge Godoy <[EMAIL PROTECTED]> writes:
> "Roger Espinosa" <[EMAIL PROTECTED]> writes:
>
> > In systems that don't have structured field names (Python (by default)
> > and Perl), I've:
> >
> > * kept track of the "identifier" in a hidden, repeated form element
> > (e.g. "active_ids")
> > * then prefixed the actual field names with that id, e.g. "001:name",
> > "001:title"
>
> This is more or less what I was thinking about. Generating the skeleton of
> the table just with headers and then generating the table with the input
> fields with JS and using swapDOM to replace the skeleton with the real table.
> I'd use something like you said (I thought about name-1, title-1, name-2,
> title-2, etc.).
>
> It might be the easiest solution...
OK. Here's the JavaScript code that worked like a charm (comments and
improvements are gladly welcome!):
================================================================================
var row_display = function (row) {
return TR(null, map(partial(TD, null), row));
}
var header_display = function (row) {
return TR(null, map(partial(TH, null), row));
}
Var montaTabelaLoteToxicologia = function (rows) {
var limit = rows.value;
limit++;
var content_rows = [];
for (var row = 1; row < limit; row++) {
var tempArray = []
elements = [row,
INPUT({"name": row+":code"},null),
INPUT({"name": row+":name"},null),
INPUT({"name": row+":age", "size":4, "maxlength":3},null),
[INPUT({"name": row+":sex", "value":"m", "type":"radio"},
null), "male",
INPUT({"name": row+":sex", "value":"f", "type":"radio"},
null), "female"],
INPUT({"name": row+":medication" },null)
];
extend(tempArray, new Array(elements));
extend(content_rows, tempArray);
}
t = TABLE({"id": "tabela_lote", "name" : "tabela_lote"},
THEAD(null, header_display(["", "Code", "Name", "Age", "Sex",
"Medication"])),
TFOOT(null, TR(null, TD())),
TBODY(null, map(row_display, content_rows)));
swapDOM("tabela_lote", t);
};
================================================================================
My HTML template *before* creating this table looks like:
================================================================================
<table id="tabela_lote">
<thead>
<tr>
<th></th>
<th>Code</th>
<th>Name</th>
<th>Age</th>
<th>Sex</th>
<th>Medication</th>
</tr>
</thead>
<tbody>
<tr>
<td align="right">1</td>
<td><input name="1:code" id="1:code" /></td>
<td><input name="1:name" id="1:name" /></td>
<td><input name="1:age" id="1:age" size="4" maxlength="3" /></td>
<td><input name="1:sex" id="1:sex" value="m" type="radio">male</input>
<input name="1:sex" id="1:sex" type="radio"
value="f">female</input></td>
<td><input name="1:medication" id="1:medication" /></td>
</tr>
</tbody>
</table>
================================================================================
If you don't provide an 'id' to the DOM generated table, it won't be replaced
when the value for the ammount of rows change. This might be good, or not.
If it is replaced, filled in values are erased and a new table is put in place
of the old one...
Be seeing you,
--
Jorge Godoy <[EMAIL PROTECTED]>