I am developing a faceted search system. Below the search box, there’s a radio select widget that has the options:
O New search O Within your results
When the page is loaded, new search should be selected by default, so I’m using the initial keyword for that.
The problem I have is that after a user selects New search and places a query, I want the default to be switched to Within your results, since most searches are refinements.
So what I need to do is change the value the user submitted, which is stored in a Django Form.
How can I change the value of the form field? Validation has already occurred, and from what I have gathered so far, request.GET is immutable (probably a good thing), and I can’t change the Form either.
Just an idea, instead of hacking the user input you could show that field only when you have a query parameter for the search.
This way the first time the user ‘hit’ the view he doesn’t see the useless radio field.
e.g. here I would use the searching param during the __init__ of the form to set the field as hidden and with the right initial value ( you can also do something like DrTysa suggested and move the searching detection at form level looking at the data dict)