[albatross-users] revisiting checkboxes..

Andrew McNamara andrewm at object-craft.com.au
Thu Jun 26 12:46:12 EST 2003


>name should've been namexpr.  name gives me:
>
><input type="checkbox" onclick="CCA(this,'mystery');DownReset();" 
>name="'token'+spamtrap_token" value="on">
>
>it's an interesting form but not what I wanted.  On the other hand
>nameexpr yields
>
><input type="checkbox" onclick="CCA(this,'mystery');DownReset();" 
>name="tokenf2952773fad60176" value="on">

Ah yes - I missed picking this up... 8-)

>now all I'm left with figuring out is how to turn on or off the checkbox
>(and maybe how to retrieve data... ;-)

Albatross evaluates the resulting name and compares it to the value
attribute (or evaluated expr/valueexpr) and adds a "checked" attribute
if they're equal:

    >>> import albatross
    >>> ctx = albatross.SimpleContext('.')
    >>> ctx.locals.foo = 'yes'
    >>> ctx.locals.name = 'foo'
    >>> albatross.Template(ctx, '<magic>', '''<al-input type="checkbox" nameexpr="name" value="yes">''').to_html(ctx)
    >>> ctx.flush_content()
    <input type="checkbox" name="foo" value="yes" checked>

On submission, all the inputs are merged back into ctx.locals. If the
checkbox is checked, it's value will be whatever the value attribute
resolves to, if not checked, it's None (from memory).

So, in the above example, on submission, you would have a variable
ctx.locals.foo with value 'yes' or None (I think 8-).

-- 
Andrew McNamara, Senior Developer, Object Craft
http://www.object-craft.com.au/



More information about the Albatross-users mailing list