Forum OpenACS Q&A: HTML id attribute in formwidget output

Hi,

We're presently making a table-less, XHTML/CSS compliant form template.

We want to use the FOR attribute in the LABEL tag to reference INPUT elements. So I have this line:

<label for="@elements.form_id@:elements:@elements.id@">@elements.label;noquote@</label>

The FOR attribute is very long on purpose, to avoid any ID name clashes in the HTML page.

Now, for the label to be useful (i.e. you can click on them and the referenced INPUT gains focus), the INPUT has to have the same ID as the label's FOR attribute. Unfortunately, the FORMWIDGET template tag does not add an ID attribute to its output. Adding the ID attribute to the FORMWIDGET is not an option, as it is already used to reference the tcl form element.

So, is there a "magic" attribute to FORMWIDGET that will translated to a simple ID attribute in the generated HTML or do I need to hack the widget procs to add such a thing myself?

Thanks!

Collapse
Posted by Demon Cypher on
Hi,
if you are looking for some thing like this

input type="text" name="test" id="test"

than use the html option in the widget

ad_form -form {
{test:text(text) {label "test"} {html "id test"}}
}

hope that helps..

Collapse
Posted by Alexandre Simard on
Thanks. I know this could work, but it would require me to add the html parameter to all my form elements in ad_form, strictly for presentation purposes. It's not clean.

What I would like is something like what the FORMGROUP tag does, where @formgroup.widget will print an <OPTION> or <INPUT TYPE="radio"> with an auto-generated ID of the following format: @elements.form_id@:elements:@elements.id@:mailto:\@formgroup.option@

Why couldn't the standard FORMWIDGET tag do something similar for other form inputs?

Collapse
Posted by Alexandre Simard on
For the record, I ended up modifying the widget procs in order to get valid XHTML, including wrapping all instances of <INPUT type="hidden"> inside a <DIV>. Once we clean things up we'll submit our patch.