5.2.2.14 type="..." attribute (radio)
Description: type=
Keywords: albatross

###
5.2.2.14 `type="..."` attribute (radio)

The tag determines the generated `name` (5.2.2.5) from the `name` related attributes. Then an internal comparison value is determined by evaluating the `expr` (5.2.2.3) attribute if it is present, or by looking up the generated `name` in the execution context.

If the comparison value equals the generated `value` (5.2.2.11) attribute then the `checked` (5.2.2.2) attribute is written. Both values are converted to string before being compared.

To determine the generated `value` attribute the tag first looks for a `valueexpr` (5.2.2.12) attribute, then a `value` attribute.

For example:

    >>> import albatross
    >>> class Ctx(albatross.SimpleContext):
    ...     def input_add(self, *args):
    ...         print args
    ...
    >>> ctx = Ctx('.')
    >>> ctx.locals.swallow = 'African'
    >>> albatross.Template(ctx, '<magic>', '''
    ... <al-input type="radio" name="swallow" value="African" whitespace>
    ... <al-input type="radio" name="swallow" value="European" whitespace>
    ... ''').to_html(ctx)
    ('radio', 'swallow', 'African', 0)
    ('radio', 'swallow', 'European', 0)
    >>> ctx.flush_content()
    <input type="radio" name="swallow" value="African" checked />
    <input type="radio" name="swallow" value="European" />

The `expr` attribute can be used to generate the internal comparison value. This is then compared with the `value` attribute to control the state of the `checked` attribute.

For example:

    >>> import albatross
    >>> class Ctx(albatross.SimpleContext):
    ...     def input_add(self, *args):
    ...         print args
    ...
    >>> ctx = Ctx('.')
    >>> ctx.locals.swallows = ['African', 'European']
    >>> ctx.locals.num = 0
    >>> albatross.Template(ctx, '<magic>', '''
    ... <al-input type="radio" name="swallow" expr="swallows[num]" value="African" whitespace>
    ... <al-input type="radio" name="swallow" expr="swallows[num]" value="European" whitespace>
    ... ''').to_html(ctx)
    ('radio', 'swallow', 'African', 0)
    ('radio', 'swallow', 'European', 0)
    >>> ctx.flush_content()
    <input type="radio" name="swallow" value="African" checked />
    <input type="radio" name="swallow" value="European" />

The `valueexpr` attribute can be used to dynamically generate the `value` attribute.

For example:

    >>> import albatross
    >>> class Ctx(albatross.SimpleContext):
    ...     def input_add(self, *args):
    ...         print args
    ...
    >>> ctx = Ctx('.')
    >>> ctx.locals.swallows = ['African', 'European']
    >>> ctx.locals.num = 0
    >>> albatross.Template(ctx, '<magic>', '''
    ... <al-for iter="s" expr="swallows">
    ... <al-input type="radio" name="swallow" expr="swallows[num]" valueexpr="s.value()" whitespace>
    ... </al-for>
    ... ''').to_html(ctx)
    ('radio', 'swallow', 'African', 0)
    ('radio', 'swallow', 'European', 0)
    >>> ctx.flush_content()
    <input type="radio" name="swallow" value="African" checked />
    <input type="radio" name="swallow" value="European" />

After writing all tag attributes the execution context `input_add()` method is called with the arguments; input field type (`'radio'`), the generated `name`, the generated `value`, and a flag indicating whether or not the `list` (5.2.2.4) attribute was present.