Skip to content

Commit

Permalink
Preserving form input
Browse files Browse the repository at this point in the history
  • Loading branch information
bradtraversy committed Sep 28, 2018
1 parent bd1caf4 commit 5e746ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
3 changes: 2 additions & 1 deletion listings/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def search(request):
'state_choices': state_choices,
'bedroom_choices': bedroom_choices,
'price_choices': price_choices,
'listings': queryset_list
'listings': queryset_list,
'values': request.GET
}

return render(request, 'listings/search.html', context)
22 changes: 17 additions & 5 deletions templates/listings/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@
<div class="form-row">
<div class="col-md-4 mb-3">
<label class="sr-only">Keywords</label>
<input type="text" name="keywords" class="form-control" placeholder="Keyword (Pool, Garage, etc)">
<input type="text" name="keywords" class="form-control" placeholder="Keyword (Pool, Garage, etc)" value="{{ values.keywords }}">
</div>

<div class="col-md-4 mb-3">
<label class="sr-only">City</label>
<input type="text" name="city" class="form-control" placeholder="City">
<input type="text" name="city" class="form-control" placeholder="City" value="{{ values.city }}">
</div>

<div class="col-md-4 mb-3">
<label class="sr-only">State</label>
<select name="state" class="form-control">
<option selected="true" disabled="disabled">State (All)</option>
{% for key,value in state_choices.items %}
<option value="{{ key }}">{{ value }}</option>
<option value="{{ key }}"
{% if key == values.state %}
selected
{% endif %}
>{{ value }}</option>
{% endfor %}
</select>
</div>
Expand All @@ -37,15 +41,23 @@
<select name="bedrooms" class="form-control">
<option selected="true" disabled="disabled">Bedrooms (Any)</option>
{% for key,value in bedroom_choices.items %}
<option value="{{ key }}">{{ value }}</option>
<option value="{{ key }}"
{% if key == values.bedrooms %}
selected
{% endif %}
>{{ value }}</option>
{% endfor %}
</select>
</div>
<div class="col-md-6 mb-3">
<select name="price" class="form-control">
<option selected="true" disabled="disabled">Max Price (All)</option>
{% for key,value in price_choices.items %}
<option value="{{ key }}">{{ value }}</option>
<option value="{{ key }}"
{% if key == values.price %}
selected
{% endif %}
>{{ value }}</option>
{% endfor %}
</select>
</div>
Expand Down

0 comments on commit 5e746ea

Please sign in to comment.