Forum OpenACS Q&A: Can ad_form do what I want it to do?

I have a table displaying the following columns: item_id, title, last_scanned, updates, and feed_url (item_id being a checkbox).

I build the form:

db_multirow sources sources { *SQL* }

ad_form -name delete_subscription -form {
    {source_id:text(checkbox) {label ""} }
    {delete_submit:text(submit) {label "Unsubscribe" } }
}
And display it:
<table cellspacing=1 cellpadding=5 border=0 width="100%">
        <formtemplate id="delete_subscription">
        <multiple name="sources">
            <tr bgcolor="#ffffff">
              <td><formwidget id="source_id"></td>
              <td><a href="@sources.link@" title="@sources.description@">@sources.title@</a></td>
              <td>@sources.last_scanned@</td>
              <td>@sources.updates@</td>
              <td><a href="@sources.feed_url@"><img src="@xml_graphic_url@" width="36" height="14" border="0" \
alt="Click to view the current XML source text for the channel." title="Click to view the current XML source t\
ext for the channel." /></a></td>
            </tr>
          </multiple>
          </formtemplate>
        </table>
Of course, since I didn't specify any values for the checkbox element, it is displayed as follows:
<input type="checkbox" name="source_id" />
Had I only been displaying a multirow datasource, I would've used <multiple>. Had I only been displaying a form, I would've used <formgroup>. So I need a way to display checkboxes and a multirow datasource alongside. The way I see it there are two ways of doing this. Either by building a widget that accepts a multirow datasource and turns it into a table with nice checkboxes or something along the lines of:
<formwidget id="source_id" value="@sources.source_id@">
to make the checkbox values coincide with multirow datasource.

Or perhaps someone have already done this?

/Simon

Collapse
Posted by Simon Carstensen on
I have a table displaying the following columns: item_id, title, last_scanned, updates, and feed_url (item_id being a checkbox).

I meant source_id, of course, not item_id...

Collapse
Posted by Don Baccus on
Since you want to emit multiple rows, you should be building one form element per row in your sources multirow.

ad_form -extend lets you do this.  You'll need to number the checkboxes ... source_id_$i something like that?

Then perhaps you could write a custom widget that build the HTML for one row, and in your template begin and end the table that holds the widget rows.

Something along these lines, perhaps?  Just thinking off the top of my head...

Collapse
Posted by Don Baccus on
Oh, you can use "source_id" over and over again because you're passing the actual id as the value of the checkbox.  Now I see...

Anyway ... build it row-by-row as I described above, I do think that's the easiest approach.

You probably don't really need to write a widget, just a form template that puts out what you want for each row.  I don't think you can do what you want with a single form element for all the source_ids, though ...

Collapse
Posted by Simon Carstensen on
Thanks, Don, for your ideas.

Personally I'd prefer the <input type="checkbox" name="source_id" value="@items.item_id@" /> tag. It seems much simpler than any little hack I can think of. Am I mixing things together?

WRT to your solution, Don, I initially tried:

item_id_$rownum
But got an error. Is there a way to access $rownum as opposed to using $i?

Using source_id_$i I'm not sure how to set $i initially. I can't set $i before running multirow, since the variables inside are all local (right?) and of course not during either.

How should I do this?

/Simon

Collapse
Posted by Simon Carstensen on
I got it working, but chose to forget about it! It just got too ugly compared to sticking a nice HTML input tag in the .adp page!

That still doesn't change my request for the addition of the value parameter to the formwidget tag, which would let me assign values to formwidget inside a multiple tag.

Collapse
Posted by Dave Bauer on
Simon,

You create the form elements in your .tcl file. The value of the element should be set there.

All the formwidget tag does is allow you to format the output, that is, put the checkboxes where you want them.