[albatross-users] Form state problem

Dave Cole djc at object-craft.com.au
Wed Oct 30 10:27:45 EST 2002


> Hi all, The following albatross template code is giving me some
> trouble and I can't see why:
> 
>     <al-form method="POST">
>     <al-input type="checkbox" name="custom_form" value="yes"> Enable
> Custom Form
>     <table>
>     <tr>
>         <td>Displayed</td>
>         <td>Field Name</td>
>         <td>Ordering</td>
>     <tr>
>     <al-for iter="r" expr="((1,'One'),(2,'Two'))">
>     <al-exec expr="chkbox.append(None); cfid.append(None);
> order.append(None)">
>     <tr>
>         <td><al-input type="checkbox" nameexpr="'chkbox[%d]' %
> r.count()" value="yes">
>             <al-input type="hidden" nameexpr="'cfid[%d]' % r.count()"
> expr="r.value()[0]"></td>
>         <td><al-value expr="r.value()[1]"></td>
>         <td><al-input type="text" size="2" nameexpr="'order[%d]' %
> r.count()"></td>
>     </tr>
>     </al-for>
>     <tr>
>         <td colspan="2"><al-input type="submit" name="submit" value="<-
> Step 4"></td>
>         <td align="right"><al-input type="submit" name="submit"
> value="Step 6 ->"></td>
>     </tr>
>     </table>
>     </al-form>
> 
> 	All the fields are set in the session and set to None or as an
> empty list.  The problem is if I check the first checkbox (One) the
> value of order[0] becomes "yes".  I've had this same code work on a
> one page form, but now has trouble when it one form of many in a
> sequence.  I'm not doing anything to the values (yet), just trying
> to make sure the state gets set on all fields before going on.  Any
> clues would be greatly appreciated.

Are you doing something like this in your code:

        ctx.locals.chkbox = ctx.locals.order = []
        ctx.add_session_vars('chkbox', 'order')

That is the thing I can think would lead to the problem you are
seeing.  If chkbox and order refer to the same list then setting one
will also set the other.  You should be initialising like this

        ctx.locals.chkbox = []
        ctx.locals.order = []
        ctx.add_session_vars('chkbox', 'order')

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list