Vote count:
0
I have a search form where in normal page, I would like to hide the a field with an initial value in it. But in certain page (in Advanced Search), I would to show the field to the user. How can I get it done in the form init?
eg. The forms.py
class SearchForm(forms.Form):
keyword = forms.CharField(label="Keyword", required=True)
cat = forms.CharField(required=True, default='1')
def __init__(self, *args, **kwargs):
super(SearchForm, self).__init__(*args,**kwargs)
self.fields['cat'].widget = forms.HiddenInput()
The above only hide the 'cat' field. How to I control the field base on the url? The urls.py:
url(r'^advance-search/$', views.AdvancedSearch, name='adv-search'),
How to passing the url to the form init? And what parameter should I check for to identify if it is the advance search page?
asked 23 secs ago
How to hide from field based on url
Aucun commentaire:
Enregistrer un commentaire