Hi Antony

My selectable looks like :

selectable = [('Add 100 to price',lambda ids: redirect(URL('product', 
'modify_price', args=request.args, vars=dict(id=ids, inc=100)))),


and my function in the product controller looks like this:

def modify_price():

if type(request.vars.id) is str:

    id_list = request.vars.id.split(',') #convertint to list

else:

    id_list = request.vars.id

db(db.product.id.belongs(id_list)).update(product_price=db.product.product_price+request.vars.inc)


 Simply following the documentation in the book

I also tried:

selectable=  lambda ids: modify_price


But the function neve called

It should be request.vars.records, not request.vars.id.


Also tried with 

def modify_rule_end_time():

print request.vars.records 


and 

def modify_rule_end_time(ids):

print ids

But again no error and the function was not called

On Friday, April 19, 2019 at 9:39:51 PM UTC+2, Anthony wrote:
>
> It should be request.vars.records, not request.vars.id.
>
> Note, request.vars is processed by the core framework, not by 
> SQLFORM.smartgrid, so it will be a single value if the browser sends only 
> one "records" field in the form data and a list otherwise. The core code 
> that populates request.vars has no way of knowing that a given field 
> containing a single value is supposed to be a list -- that has to be 
> handled elsewhere. SQLFORM.smartgrid itself handles this properly, but if 
> you are going to intercept request.vars and run some custom code outside of 
> the grid, then it is up to you to do the check and convert to a list.
>
> Keep in mind, the "selectable" argument to the grid should be a function 
> that takes the list of ids -- presumably you can move your code into that 
> function, in which case, you won't have to worry about this, as the grid 
> will handle the conversion to a list.
>
> Anthony
>
> On Friday, April 19, 2019 at 9:28:21 AM UTC-4, icodk wrote:
>>
>> SQLFORM.smartgrid selectable  return string if only one checkbox was 
>> slected and returns a list if 2 or more was selected.
>> This  inconsitancy force me to check for type before processing can 
>> continue
>> For example, If I have a button that update selected records in the 
>> database call a function that do:
>>
>>
>> db(db.product.id.belongs(request.vars.id)).update(price=db.product.price+request.vars.inc_price)
>>
>>
>> However if only one line selected in the grid request.vars.id is a string 
>> and not a list, which cause an error
>>
>>

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

Reply via email to