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