Hi, I am trying to do the same thing as the OP. Add a quantity input field to a grid and then use Callback to work with the product_id and quantity. I just don't seem to be able to pass the quantity to the callback function.
Using this method I don't get a value from quantity. links=[ lambda row: INPUT(_type='number', _value=0, _name='qty'), lambda row: A(T('Add'), callback=URL('_add_product',args=[row.id, request.vars.qty]), _class='button btn btn-default') ] ) If I use args or vars doesn't matter. The point is I always get 'None' for the Quantity field. I have tried wrapping the grid in a form and the input in a form. I am sure I am doing something simple wrong. Here's the whole function: @auth.requires_login() def product_add(): productid = request.args(0) grid = SQLFORM.grid(db.product.id == productid, args=[productid], create=False, editable=False, deletable=False, fields=[db.product.productname, db.product.purchasecost, db.product.monthlycost, db.product.smallimage], links=[ lambda row: FORM(INPUT(_type='number', _value=0, _name='qty')), lambda row: A(T('Add'), callback=URL('_add_product', vars=dict(productid=productid, qt=request.vars.qty)), _class='button btn btn-default') ] ) return locals() On Friday, 13 April 2012 21:26:56 UTC+2, greenpoise wrote: > > Richard, > > I tried Massimos approach but it created one form button rather than one > for each row. For my uses, it wont cut it. I need one text field plus a > button on each row. I was able to accomplish this like this > > links = [lambda row: INPUT(_name='qty', _value='1'), lambda row: A('+', > callback=URL('cart_callback',vars=dict(id=row.id,action='add',qt=request. > vars.qty)))] > > Maybe I did not make myself clear but I just want to have a product grid > with all the products and the qty. Sort of a storefront, so the input text > is not db attached. Click on the button and add it to my cart.. Hmmm but it > seems you want to have like a bulk functionality with the grid, right??? > > > > > > > On Thursday, 12 April 2012 14:27:53 UTC-7, Richard wrote: >> >> Hello Danel, >> >> May I see screenshot of what Massimo propose? >> >> I mean I would be really interrested in a bulk entry capability too. >> >> If it is already available I would know I was about to make a custom >> mechanism to allow user to add many result at the same time that would rely >> on Excel and validate_and_insert web2py method... >> >> The problem I had was to read directly Excel file, I would need to write >> a lot of code with xlrd. If I can avoid that I will be happy :) >> >> Thanks. >> >> Richard >> >> On Thu, Apr 12, 2012 at 5:14 PM, greenpoise <danel....@gmail.com >> <javascript:>> wrote: >> >>> Massimo, >>> >>> where do I change the INPUT size (length, width)? >>> >>> >>> >>> links = [lambda row: INPUT(_name='quantity', _class='integer', _value=1)] >>> >>> >>> >>> >>> >>> On Wednesday, 11 April 2012 18:34:16 UTC-7, Massimo Di Pierro wrote: >>>> >>>> yes and not and what I said needs clarification. >>>> >>>> grid = SQLFORM.grid(create=False,update=False) is not a form. If >>>> create=True or update=True then it contains a form when you are creating >>>> or >>>> updating a record. you must avoind a form within a form and you can do so >>>> in the view: >>>> >>>> {{if grid.create_form or grid.update_form:}} >>>> {{=grid}} it is a form >>>> {{else:}} >>>> <form>{{=grid}} it is not a form but you can embed it in one <input >>>> type='submit'/></form> >>>> {{pass}} >>>> >>>> >>>> On Wednesday, 11 April 2012 20:23:08 UTC-5, greenpoise wrote: >>>>> >>>>> A bit confused..I thought SQLFORM.grid was itself a form? Also, can I >>>>> add more than one link per grid? Reading from the book, it creates a >>>>> column >>>>> so technically sounds as if I could??? >>>>> >>>>> On Wednesday, 11 April 2012 16:27:17 UTC-7, Massimo Di Pierro wrote: >>>>>> >>>>>> You can put the grid in a form and you add >>>>>> >>>>>> SQLFORM.grid(..., link=[lambda row: INTPUT(...)]) >>>>>> >>>>>> On Wednesday, 11 April 2012 17:07:58 UTC-5, greenpoise wrote: >>>>>>> >>>>>>> Is this possible?? I have a products table that shows all the >>>>>>> products. I also created an add to cart button in it problem is if I >>>>>>> want >>>>>>> to add 100 items I would have to press the button 100 times. Is there >>>>>>> a >>>>>>> way to add a quantity text field??? >>>>>>> >>>>>>> >>>>>>> Thanks >>>>>>> >>>>>>> Dan >>>>>>> >>>>>> >>>>> On Wednesday, 11 April 2012 16:27:17 UTC-7, Massimo Di Pierro wrote: >>>>>> >>>>>> You can put the grid in a form and you add >>>>>> >>>>>> SQLFORM.grid(..., link=[lambda row: INTPUT(...)]) >>>>>> >>>>>> On Wednesday, 11 April 2012 17:07:58 UTC-5, greenpoise wrote: >>>>>>> >>>>>>> Is this possible?? I have a products table that shows all the >>>>>>> products. I also created an add to cart button in it problem is if I >>>>>>> want >>>>>>> to add 100 items I would have to press the button 100 times. Is there >>>>>>> a >>>>>>> way to add a quantity text field??? >>>>>>> >>>>>>> >>>>>>> Thanks >>>>>>> >>>>>>> Dan >>>>>>> >>>>>> >> -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.