Forum OpenACS Development: Preselecting option tags in template multiple

So I got this bit of code:

<select id="uid" size="20" name="uid>
    <multiple name="user">
        <if @user.prev_group@ nil or @user.group_name@ ne @user.prev_group@>
            <optgroup label="@user.group_name@">
        </if>

        <option <if @user_id@ eq @user.user_id@>selected</if> value="@user.user_id@">@user.user_name@</option>

        <if @user.next_group@ nil or @user.group_name@ ne @user.next_group@>
            </optgroup>
        </if>
    </multiple>
</select>
(user_id is in ad_page_contract)
The problem is the "selected" attribute always gets rendered as ' selected="" ', which doesn't actually cause an option to be selected. Am I missing something?

Collapse
Posted by Gustaf Neumann on
Dear hsin,

i can't reproduce the problem as described, but i see two issues in the given example: (a) there is a missing double quote after "uid" in the "select" opening tag. (b) in order to group data, one should use the "group" tag of OpenACS for best results. See the following example:

hsin.tcl:

set user_id 123
template::multirow create user user_name user_id group_name

template::multirow append user "Joe Dalton" 122 villain
template::multirow append user "William Dalton" 123 villain
template::multirow append user "Jack Dalton" 124 villain
template::multirow append user "Averell Dalton" 125 villain
template::multirow append user "Luky Luke" 126 cowboy
hsin.adp:
<master>
<form>
<select id="uid" size="8" name="uid">
  <multiple name="user">
    <optgroup label="@user.group_name@">
      <group column="group_name">
        <option <if @user_id@ eq @user.user_id@>selected</if> value="@user.user_id@">@user.user_name@</option>
      </group>
    </optgroup>
  </multiple>
</select>
</form>
result:

This is tested with the current version in the oacs-5-9 branch.

Hope this helps, all the best
-gn

Collapse
Posted by hsin wang on
Hello Gustaf,

Thanks for your detailed reply. I have switched my code over to use the group tag, which I agree is a much better way to go about it. The missing double quote was actually just a typo; it is in fact there in my code.

The output I get at the selected line becomes:
<option selected="" value="4">Jack Brown (JB-102)</option>

the ="" is generated and preventing an actual selection on the option (at least Firefox). In the screenshot you provided, does the ="" get generated in the source?

am on oacs-5-9 branch as well.

Collapse
Posted by Gustaf Neumann on
Strange. The screenshot above was made with ff 49, The raw HTML is below (double checked the raw output which is sent from the server to the browser):
<form>
<select id="uid" size="8" name="uid">
    <optgroup label="villain">
        <option  value="122">Joe Dalton</option>
        <option selected value="123">William Dalton</option>
        <option  value="124">Jack Dalton</option>
        <option  value="125">Averell Dalton</option>
    </optgroup>
    <optgroup label="cowboy">
         <option  value="126">Luky Luke</option>
     </optgroup>
</select>
</form>
I see no chance, how the the equals and the quotes are inserted by the template above. Are you sure, you have no plugin etc. installed, that processes the results? try to check with wget, what the server sends back.

-gn

Collapse
Posted by hsin wang on
Hi Gustaf,

I've checked with our admin and it seems we may have some plugins that could cause the effect. I've put in a ticket on our end. If we find that it is an internal issue, I'll update this to resolve it as a non-issue.

Thank you for your time and patience.

- Hsin

Collapse
Posted by hsin wang on
Update:

It turns out Firefox automatically adds the ="" at the end of an attribute without assigned values. My issue was a result of that fact on top of a Javascript preset and I mistook the former to be the cause.

Thank you for taking your time to troubleshoot this with me.

Hsin