5.2.2.15 type="..." attribute (checkbox)
Description: type=
Keywords: albatross

###
5.2.2.15 `type="..."` attribute (checkbox)

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.

If the internal comparison value is either a list or tuple the `checked` attribute is written if the generated `value` attribute is present in the list/tuple.

To determine the generated `value` attribute the tag first looks for a `valueexpr` (5.2.2.12) attribute, then a `value` attribute, and then if that fails it defaults to the value `'on'`.

For example:

    >>> import albatross
    >>> class Ctx(albatross.SimpleContext):
    ...     def input_add(self, *args):
    ...         print args
    ...
    >>> ctx = Ctx('.')
    >>> ctx.locals.menu = ['spam', 'eggs']
    >>> ctx.locals.eric = 'half'
    >>> ctx.locals.parrot = 'on'
    >>> ctx.locals.halibut = 'off'
    >>> albatross.Template(ctx, '<magic>', '''
    ... <al-input type="checkbox" name="menu" value="spam" whitespace>
    ... <al-input type="checkbox" name="menu" value="eggs" whitespace>
    ... <al-input type="checkbox" name="menu" value="bacon" whitespace>
    ... <al-input type="checkbox" name="eric" value="half" whitespace>
    ... <al-input type="checkbox" name="parrot" whitespace>
    ... <al-input type="checkbox" name="halibut" whitespace>
    ... ''').to_html(ctx)
    ('checkbox', 'menu', 'spam', 0)
    ('checkbox', 'menu', 'eggs', 0)
    ('checkbox', 'menu', 'bacon', 0)
    ('checkbox', 'eric', 'half', 0)
    ('checkbox', 'parrot', 'on', 0)
    ('checkbox', 'halibut', 'on', 0)
    >>> ctx.flush_content()
    <input type="checkbox" name="menu" value="spam" checked />
    <input type="checkbox" name="menu" value="eggs" checked />
    <input type="checkbox" name="menu" value="bacon" />
    <input type="checkbox" name="eric" value="half" checked />
    <input type="checkbox" name="parrot" value="on" checked />
    <input type="checkbox" name="halibut" value="on" />

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