Re: [web2py] Re: How to add an input field in SQLFORM.grid??

2016-11-28 Thread Paul Ellis
What about if I don't use 'callback' but 'href' so it loads the whole page. 
I still can't get the quantity value to be passed as an arg.

On Saturday, 26 November 2016 14:35:33 UTC+1, Anthony wrote:
>
> On Friday, November 25, 2016 at 11:11:41 PM UTC-5, Paul Ellis wrote:
>>
>> 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]),
>>
>
> Obviously request.vars.qty won't work here, as request.vars is not 
> populated until after the request arrives at the server. Instead, you would 
> have to use Javascript to update the callback URL whenever the value of the 
> input changes.
>
> Anthony
>

-- 
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.


Re: [web2py] Re: How to add an input field in SQLFORM.grid??

2016-11-26 Thread Anthony
On Friday, November 25, 2016 at 11:11:41 PM UTC-5, Paul Ellis wrote:
>
> 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]),
>

Obviously request.vars.qty won't work here, as request.vars is not 
populated until after the request arrives at the server. Instead, you would 
have to use Javascript to update the callback URL whenever the value of the 
input changes.

Anthony

-- 
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.


Re: [web2py] Re: How to add an input field in SQLFORM.grid??

2016-11-25 Thread Paul Ellis
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 > > 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:}}
 {{=grid}} it is not a form but you can embed it in one >>> type='submit'/>
 {{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 

Re: [web2py] Re: How to add an input field in SQLFORM.grid??

2012-05-25 Thread Richard Vézina
Hello Massimo,

May I use this SQLFORM.grid capability to create a bulk or batch insert
feature?

I am having problem with form validation and update of record actually. I
try to update a record for now :

Controller :
def grid_into_form():
grid = SQLFORM.grid(db.tab1,
_class=web2py_grid,
links=[lambda row: INPUT(_name='result', _class='decimal')],
create=True,
editable=True,
paginate=5)
return dict(grid=grid)

View :
form{{=grid}}input type='submit'//form

I get input for every records in the table. But since I use html form tag I
wonder how I could use validators... I try to put the grid in a form at the
controller level like this (not successfully) :
def grid_into_form():
grid = SQLFORM.grid(db.tab1,
_class=web2py_grid,
links=[lambda row: INPUT(_name='result', _class='decimal')],
create=True,
editable=True,
paginate=5)
form = FORM(grid)
if form.accepts(request,session):
response.flash = 'form accepted'
elif form.errors:
response.flash = 'form has errors'
else:
response.flash = 'please fill the form'
return dict(form=form)

Also, how could I generate a grid of say 20 rows with only blank input for
every fields of a given table (so kind of empty rows)?

Thanks

Richard



On Wed, Apr 11, 2012 at 9:34 PM, Massimo Di Pierro 
massimo.dipie...@gmail.com 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




Re: [web2py] Re: How to add an input field in SQLFORM.grid??

2012-04-13 Thread greenpoise
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.sega...@gmail.comwrote:

 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




Re: [web2py] Re: How to add an input field in SQLFORM.grid??

2012-04-13 Thread Richard Vézina
Yes I think I miss understood... What I would have is the capability to
insert many records in one operation (one form submission). I thought that
what Massimo suggest turn the SQLFORM.grid in a kind of multiples rows form
or something like that. It was not actually clear what Massimo was doing
what Massimo suggested. That why I ask you if you were willing to show a
screenshot of the result.

Don't mind if I actually miss understand.

Cheer.

Richard

On Fri, Apr 13, 2012 at 3:26 PM, greenpoise danel.sega...@gmail.com 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.sega...@gmail.comwrote:

 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,**upda**te=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





Re: [web2py] Re: How to add an input field in SQLFORM.grid??

2012-04-13 Thread greenpoise
Richard,
you know what? maybe it does what you want actually because what I get is a 
bunch of records with a txt and one submit button at the end. So, basically 
a grid within a form. I will write it and run it again and send you a 
screenshot. 




D

On Friday, 13 April 2012 12:36:29 UTC-7, Richard wrote:

 Yes I think I miss understood... What I would have is the capability to 
 insert many records in one operation (one form submission). I thought that 
 what Massimo suggest turn the SQLFORM.grid in a kind of multiples rows form 
 or something like that. It was not actually clear what Massimo was doing 
 what Massimo suggested. That why I ask you if you were willing to show a 
 screenshot of the result.

 Don't mind if I actually miss understand.

 Cheer.

 Richard

 On Fri, Apr 13, 2012 at 3:26 PM, greenpoise danel.sega...@gmail.comwrote:

 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.sega...@gmail.comwrote:

 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





Re: [web2py] Re: How to add an input field in SQLFORM.grid??

2012-04-12 Thread Richard Vézina
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.sega...@gmail.com 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