[ic] Problem with form select...

Kevin Walsh interchange-users@interchange.redhat.com
Tue Dec 18 12:09:01 2001


> First let me say that IC rocks
>
Really?  I have found it to be very stable. :-)

>
> and that this list is not only very informative but quite amusing at times :)
>
> I'm trying to set the default value of a select field on a from (using the
> [selected] tag) to an existing value from a table.  Below is a quick snippet
> of my form.  The select is always populated correctly I just cant seem to
> get it to default to the current values.
>
> [loop prefix=slist arg="[scratch sprofile_id]"]
>   <select name="category" size="1">
>     [loop prefix=scat search="ra=yes/fi=cat/rf=code,name/ml=100/tf=name" ]
>       <option value="[scat-data cat name]" [selected name=category
>              value="[slist-data sprofile category]"]>
>          [scat-data cat name]
>       </option>
>     [/loop]
>   </select>
> [/loop]
>
I don't really understand your use of the outer loop in this
context.  Will there really be more than one sprofile_id value?
I suspect not, as your <select> list has a fixed (category) variable
name.

Generally, to generate an <option> list, with a default (selected)
value, you would do something like this:

    <select name="category">
        [loop search="ra=yes/fi=cat/rf=code,name/ml=100/tf=name"
              prefix=scat
              option=category]
        <option value="[scat-param name]">[scat-param name]</option>
        [/loop]
    </select>

That will set the default (selected) option to the first one that
matches "category" value.  I suggest you simply set the "category"
value to a default before calling the above code, like this:

    [if !value category]
        [value name=category
               set="[scratch sprofile_id]"
               filter="lookup.sprofile.category"
               hide=1]
    [/if]


Just a suggestion: I see that you store the scat.name lookup values
in sprofile.category.  I think it would be better to store the
scat.code instead.  This would allow you to modify the name without
breaking things in the future, and would also save having to do that
filter lookup in the [value] tag.

--
   _/   _/  _/_/_/_/  _/    _/  _/_/_/  _/    _/
  _/_/_/   _/_/      _/    _/    _/    _/_/  _/   K e v i n   W a l s h
 _/ _/    _/          _/ _/     _/    _/  _/_/    kevin@cursor.uk.com
_/   _/  _/_/_/_/      _/    _/_/_/  _/    _/