5.2.3.7 optionexpr="..." attribute
Description: optionexpr=
Keywords: albatross

###
5.2.3.7 `optionexpr="..."` attribute

If this attribute is present the expression in the attribute value is evaluated to determine a sequence of option values. One `<option>` tag is generated for each item in the sequence.

When this attribute is not present all of the directly enclosed `<al-option>` (5.2.4) tags are processed to generate the enclosed `<option>` tags.

If an item in the `optionexpr` sequence is not a tuple, it is converted to string and then compared with the comparison value derived from the `name` (5.2.3.4) attribute.

To support multiple selected `<option>` tags the comparison value must be either a list or tuple.

For example:

    >>> import albatross
    >>> ctx = albatross.SimpleContext('.')
    >>> ctx.locals.sel1 = 3
    >>> ctx.locals.sel2 = (2,3)
    >>> albatross.Template(ctx, '<magic>', '''
    ... <al-select name="sel1" optionexpr="range(5)" whitespace/>
    ... <al-select name="sel2" optionexpr="range(5)" multiple whitespace/>
    ... ''').to_html(ctx)
    >>> ctx.flush_content()
    <select name="sel1"><option>0</option>
    <option>1</option>
    <option>2</option>
    <option selected>3</option>
    <option>4</option>
    </select>
    <select multiple name="sel2"><option>0</option>
    <option>1</option>
    <option selected>2</option>
    <option selected>3</option>
    <option>4</option>
    </select>

If an item in the `optionexpr` sequence is a tuple it must contain two values. The first value is used to specify the `value` attribute of the generated `<option>` tag and the second value provides the `<option>` tag content.

For example:

    >>> import albatross
    >>> ctx = albatross.SimpleContext('.')
    >>> ctx.locals.menu = [(1, 'Spam'), (2, 'Eggs'), (3, 'Bacon')]
    >>> ctx.locals.sel = 1
    >>> albatross.Template(ctx, '<magic>', '''
    ... <al-select name="sel" optionexpr="menu" whitespace/>
    ... ''').to_html(ctx)
    >>> ctx.flush_content()
    <select name="sel"><option selected value="1">Spam</option>
    <option value="2">Eggs</option>
    <option value="3">Bacon</option>
    </select>

All values generated by the `optionexpr` method are escaped to make all `&`, `<`, `>`, and `"` characters safe.