[albatross-users] Limitations of al-select and al-option

Dave Cole djc at object-craft.com.au
Tue Sep 30 11:43:13 EST 2003


> I'm trying to implement a drop-down menu on a form, and either the
> al-select/al-option mechanism is rather limited, or I just don't
> understand something.
> 
> Here is *my* understanding of the al-select, and please correct me if
> I am wrong:
> 
> (1) If I have a list, such as optionlist, I can do the following to
> generate an entire drop-down select menu:
> 
> <al-select name="mymenuname" optionexpr="optionlist" />

That is correct.

> However, the problem as far as I can see, with the above, is that I
> cannot get option tags that have a separate "value" attribute.
> 
> For example, if I want to display to the web site visitor some text
> data, but I want to have the form return an integer (such as a
> category ID in a MySQL table), I cannot see how I could get that from
> the above structure?

Have a closer look at the second example on this page:

    http://www.object-craft.com.au/projects/albatross/albatross/tag-select-optionexpr.html

Unless I misunderstand what you are asking, it does exactly what you
require.

> (2) I can't use an al-for to generate this either, as the al-select
> tag ignores any al-option tags that are not "direct children" of the
> al-select tag.
> 
> So it appears that I cannot generate HTML code such as:
> 
> <select name="mymenuname">
> <option value="1">option 1</option>
> <option value="2">option 2</option>
> <option value="3">option 3</option>
> </select>
> 
> If I'm missing something, and there is a way to generate HTML as shown
> above, please clue me in. Right now I'm getting around this by making
> extra MySQL queries to convert the text "option 1" into the integer
> value that I would really like the form to return for me.

What you need to do is something similar to this in your Python code:

    c.execute('SELECT id, name FROM category')
    ctx.locals.optionlist = c.fetchall()
    ctx.run_template('something.html')

When the <al-select> tag sees that each item in the option list is a
tuple it treats item differently.  It uses the first element of each
tuple as the option value and the second element as the content.

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list