Forum OpenACS Q&A: ad_form select widget default value

Using an ad_form select widget, I want to set a default value for state for a new entry.

This syntax works:
{state:text(select) {label "State"} {options {$state_list}} {value $state}}

However, the above syntax does not set any value in edit mode when the values are being pulled from the ad_form query.

Instead, this syntax works for setting a select widget value from data pulled by the ad_form query:

{state:text(select) {label "State"} {options {$state_list} {value $state}}}

(Notice the different closing brackets.)

What's the proper syntax needed to get the desired results for both scenarios?

Thanks.

Collapse
Posted by Jade Rubick on
Can you clarify what you mean by getting the desired results for both scenarios?
Collapse
Posted by James Thornton on
1. Set a select widget's value for a new entry, i.e. default value.

2. Set a select widget's value for an edit form from data pulled via the ad_form query.

The following syntax works for scenario one, but not two:
{state:text(select) {label "State"} {options {$state_list}} {value $state}}

The following syntax works for scenario two, but not one:
{state:text(select) {label "State"} {options {$state_list} {value $state}}}

Collapse
Posted by Jon Griffin on
Collapse
Posted by Jade Rubick on
And I'm sure you're probably aware of

http://rubick.com/openacs/ad_form  (which will be down this weekend)

But what I did on project-manager is available here:

http://cvs.openacs.org/cvs/openacs-4/contrib/packages/project-manager/

I'd look specifically at the add-edit.tcl file. The task-add-edit.tcl file doesn't actually edit, and the task-edit.tcl file only edits.

Collapse
Posted by James Thornton on
I resolved the issue by using a -new_data block, and removing all the value params, e.g. {value $state}.

Thanks Jade and Jon for writing the docs and showing me where to find them.

Collapse
Posted by James Thornton on
Oops. That should read, "I resolved the issue by using a -new_request block, and removing all the value params, e.g. {value $state}."