Thanks for the tip. That was exactly the problem. I have found I fix, it's not yet fully working but it's a work in progress.
What I'm doing is running a loop of all available forms in the dictionary and trying to accept the request.vars for each of them. It's not very efficent though, so if anyone has a better idea I would really like to hear it. Thanks a lot Anthony. On 25 ago, 09:09, Anthony <[email protected]> wrote: > If I follow correctly, when someone submits a qty_form, the search form is > not also being submitted, but because the qty_form.accepts is inside the > form.accepts, it will never get to qty_form.accepts, because form.accepts > will evaluate to False when a qty_form is submitted (I think). Even if > form.accepts passed, though, it wouldn't fetch any product id because > request.vars.search will be empty, so you still wouldn't get to > qty_form.accepts. > > Anthony > > > > > > > > On Thursday, August 25, 2011 9:50:04 AM UTC-4, Francisco wrote: > > Thanks for the help. Here is the complete function defined in the > > controller: > > > ------ code for controller starts ------ > > > @auth.requires_login() > > def new_sale(): > > response.title="New sale" > > if not session.cart: > > session.cart={} > > if not session.cart_qty: > > session.cart_qty={} > > if not session.qty_forms: > > session.qty_forms={} > > form = FORM(INPUT(_name="search", requires=IS_NOT_EMPTY()), > > INPUT(_type="submit", > > _value="Search"),_name="form_search") > > if form.accepts(request.vars,session,formname="form_search"): > > rows=db(db.products.barcode==request.vars.search).select() > > if len(rows) == 1: > > product = rows.first() > > if product.id in session.cart: > > session.cart_qty[product.id]+=1 > > session.qty_forms[product.id][0] > > ['_value']=session.cart_qty[product.id] > > else: > > session.cart[product.id]=product > > session.cart_qty[product.id]=1 > > qty_form=FORM(INPUT( _name="qty", _value=1), > > INPUT(_type="hidden", > > _name="prod_id",_value=product.id), > > > INPUT(_type="submit",_value=T("Update"),_style="display:none;"), > > _name="formqty"+str(product.id)) > > if qty_form.accepts(request.vars, > > session,formname="formqty"+str(product.id)): > > session.cart_qty[request.vars.prod_id]+=1 > > temp_qty = session.cart_qty[request.vars.prod_id] > > session.qty_forms[request.vars.prod_id][0]['_value'] = > > temp_qty > > session.qty_forms[product.id]=qty_form > > return dict(form=form) > > > ------ code for controller ends ------ > > > Now this is the view code: > > > ------ code for view starts ------ > > {{extend 'layout.html'}} > > > <h1>Venta</h1> > > > <div id="buscar_codigo"> > > {{=form}} > > </div> > > > {{if len(session.cart)>0:}} > > <table class="data_table"> > > <thead> > > <tr> > > <th scope="col" class="a10pc">Cantidad</th> > > <th scope="col" class="a10pc">Codigo</th> > > <th scope="col" class="a50pc">Producto</th> > > <th scope="col" class="a10pc">Precio</th> > > <th scope="col" class="a10pc">Sub-Total</th> > > <th scope="col" class="a10pc">Quitar</th> > > </tr> > > </thead> > > <tbody> > > {{i=0}} > > {{total=0}} > > {{for id, product in session.cart.iteritems():}} > > {{if i%2==1:}} > > <tr class="impar"> > > {{else:}} > > <tr> > > {{pass}} > > <!--So I basically read all the products in the cart (a > > dictionary) > > Each product must have a quantity form so the user > > can modify the amount of > > products sold.--> > > <td>{{=session.qty_forms[id]}}</td> > > <td>{{=session.cart[id].codigo_de_barras}}</td> > > <td>{{=session.cart[id].nombre}}</td> > > <td>{{=session.cart[id].precio_de_venta}}</td> > > > <td>{{=session.cart[id].precio_de_venta*session.cart_qty[id]}}</td> > > <td></td> > > </tr> > > {{i+=1}} > > {{total > > +=session.cart[id].precio_de_venta*session.cart_qty[id]}} > > {{pass}} > > <tfoot> > > <tr class="total_row"> > > <th align="right" colspan="3" class="total"><strong>Total</ > > strong></td> > > <th colspan="3" class="total"><strong>{{=total}}</strong></ > > td> > > </tr> > > </tfoot> > > </tbody> > > </table> > > {{pass}} > > ------ code for view ends ------ > > > Hopefully this time indentation wont break. Any way as I already said > > the forms display correctly is just that the accept code doesn't. And > > my forms all have different names. Hope some one can give a hand. > > > Thanks.

