SQLFORM.grid search with custom request.vars

262 views
Skip to first unread message

Paolo Valleri

unread,
May 5, 2014, 8:28:41 AM5/5/14
to web...@googlegroups.com
Dear all,
I've implemented a method which uses SQLFORM.grid to show a subset of a given table. The query that defines the subset is built using a variable passed to the method through request.vars.*.
Everything works as expected but search, namely when I type search for something all former request.vars are erased.
Actually the action url of the form is correct it has all request.vars variable plus the signature, when I type search all of them are replaced by the variable 'keywords'
Is this the expected behavior for SQLFORM.grid search?

Regards
Paolo

Richard Vézina

unread,
May 5, 2014, 11:30:15 AM5/5/14
to web2py-users
Maybe there is a need for vars property that could work similarily as args of SQLFORM.grid?

Richard


--
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+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Paolo Valleri

unread,
May 6, 2014, 11:49:06 AM5/6/14
to web...@googlegroups.com
If I change the search form action to POST the whole url is preserved, and the keywords variable is passed as request payload. However the search doesn't work, I guest I have to change sqlform.grid in order to allows vars as post_vars, is there a specific reason for having the search action as GET?

 Paolo


You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/xlQfmCUZci0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Anthony

unread,
May 6, 2014, 1:23:48 PM5/6/14
to web...@googlegroups.com
On Tuesday, May 6, 2014 11:49:06 AM UTC-4, Paolo Valleri wrote:
If I change the search form action to POST the whole url is preserved, and the keywords variable is passed as request payload. However the search doesn't work, I guest I have to change sqlform.grid in order to allows vars as post_vars, is there a specific reason for having the search action as GET?

I think GET is the appropriate HTTP verb when requesting resources (as opposed to inserting/creating them).

Anthony

Anthony

unread,
May 6, 2014, 2:55:07 PM5/6/14
to web...@googlegroups.com
I think when the browser makes the request, it strips any existing query string from the form action and replaces it with a query string containing the form data. A workaround would be to include hidden fields in the form that contain the original query string variables. This could be done in the server side code or via JavaScript. The advantage of the latter is that it could more easily be made to work with custom search widgets (also possible on the server side, but would be difficult if the custom widget is not a web2py FORM object).

Maybe submit a Google issue and link to this thread.

Anthony

Paolo Valleri

unread,
May 7, 2014, 4:00:33 AM5/7/14
to web...@googlegroups.com
The workaround of the hidden fields seems to be much more complex for this simple issue, isn't it?
In this specific case, we make a search in my point of view the most appropriate action should be a POST since we submit data to be processed. A drawback of that change will be that with the post, a user is not able to bookmark the search result.

 Paolo


--

Anthony

unread,
May 7, 2014, 9:24:38 AM5/7/14
to web...@googlegroups.com
On Wednesday, May 7, 2014 4:00:33 AM UTC-4, Paolo Valleri wrote:
The workaround of the hidden fields seems to be much more complex for this simple issue, isn't it?
In this specific case, we make a search in my point of view the most appropriate action should be a POST since we submit data to be processed. A drawback of that change will be that with the post, a user is not able to bookmark the search result.

In addition to not allowing bookmarking, POST will cause problems if the user does a refresh or hits the back button (i.e., the browser will ask if you want to re-submit the form data). Anyway, I think the hidden fields could be added with a few lines of code, so shouldn't be too complex.

Anthony 

Paolo Valleri

unread,
May 8, 2014, 4:22:14 AM5/8/14
to web...@googlegroups.com

Alfonso de la Guarda Reyes

unread,
Oct 18, 2014, 2:57:46 PM10/18/14
to web...@googlegroups.com
Hi,

Any change about this? or at lesat how to solve?

Alen Cerovic

unread,
Oct 24, 2014, 3:47:38 PM10/24/14
to web...@googlegroups.com
I am on the same boat, any solutions?

Alen Cerovic

unread,
Nov 28, 2014, 11:10:26 AM11/28/14
to web...@googlegroups.com
bump, any news? This is really anoying not to be able to preserve vars as we can args

Paolo Valleri

unread,
Dec 19, 2014, 8:53:58 AM12/19/14
to web...@googlegroups.com
Hi, I create a PR https://github.com/web2py/web2py/pull/569 for this issue

 Paolo

--

Ashokkumar Nagarajan

unread,
Mar 13, 2016, 12:42:05 AM3/13/16
to web2py-users
Hi,

I am new to Web2Py. Currently I am stuck with this issue.

Any fix available for this issue ? Or anybody found any work around ?

Thanks,
Ashok
Reply all
Reply to author
Forward
0 new messages