[albatross-users] can't figure out why it's flipping me the bird

Matt Goodall matt at pollenation.net
Thu Sep 11 18:34:43 EST 2003


On Thu, 2003-09-11 at 01:14, Eric S. Johansson wrote:
> Matt Goodall explained:
> 
> > 
> > The error means that you have multiple al-input fields with the same
> > name, "albatross_token". There are two ways to fix that, depending on
> > what you are trying to do:
> > 
> > 1. Add a 'list' attribute to the al-input element to allow more than one
> > al-input with the same name. The name will always be the string
> > "albatross_token".
> > 2. Use a 'nameexpr' attribute rather than 'name' so that each al-input
> > has a different name. The name of the al-input will be the current value
> > of the albatross_token variable.
> > 
> > 
> >>The only reason I'm trying to set the name is so I can identify each field and 
> >>determine whether or not has changed from the previous value so I will know 
> >>whether to write it out or not.
> > 
> > 
> > OK, I think you want 2 - use a 'nameexpr' attribute.
> > 
> 
> 
> I'm doubly confused them. 

Oops, sorry ;-)


> In my first example 

Here it is again for reference:

     <al-if expr="line.value().checked=='on'">
       <al-exec expr="albatross_token = line.value().token">
     <al-else>
       <al-exec expr="albatross_token = 'off'">
     </al-if>

     <al-input type="checkbox" name="albatross_token" 
         valueexpr="line.value().token"  list
         onclick="CCA(this,'mystery');DownHalt();" >
     <td>


> you'll notice that I set the 
> value of albatross_token before using any input statement.

Yes, the albatross_token variable will be either the string 'off' or the
value of line.value().token.


> In that example, each name is set to the value of albatross_token.

The wording in your sentence is a bit ambiguous so just to clarify ...
the name of all checkbox fields will be 'albatross_token', i.e. in the
HTML each checkbox will have a name="albatross_token" attribute.

Erm, I just noticed something. Unless I'm missing something obvious
(which is quite possible!) the albatross_token variable in your example
is set but never actually used.


> I'm trying to do the same 
> thing in the second example.  As you'll see, I'm setting the value with a 
> al-exec expr... statement.  I did try the nameexpr version but you notice that I 
> also have a valueexpr to set the value of each input.  If I use nameexpr then I 
> cannot use valueexpr.

I only just realised this myself but, according to the documentation,
the valueexpr attribute will be ignored for type="text" inputs. The
value is taken from ctx.locals.


> So, how do I set the name and the value fields in each input?

Use nameexpr to give each al-input a unique name and put the values of
the data in ctx.locals. Something like the following untested code
should work:

# Some data to use
data = [
    {'token': 'a', 'value': 1},
    {'token': 'b', 'value': 2},
    ]
# Build a list of tokens
ctx.locals.tokens = [line['token'] for line in data]
# Publish the token values to ctx.locals
for line in data:
    setattr(ctx.locals, line['token'], line['value'])

<al-for iter="token" expr="tokens">
    <al-input type="text" nameexpr="token.value()" />
</al-for>

Of course, there may be a much better way of doing this.

Cheers, Matt

-- 
Matt Goodall, Pollenation Internet Ltd
w: http://www.pollenation.net
e: matt at pollenation.net
t: +44 (0)113 2252500



More information about the Albatross-users mailing list