I am trying to render a form where some fields are initialized dynamically. The issue is the form is getting all the values assigned when I print the form, but those values does not show up when rendered.
My View is:
def zoneinfo(request):
siteId = request.GET.get('siteId')
form = PostForm(site = siteId.upper())
print form
return render(request, 'details.html', {'form': form})
details.html:
{% load staticfiles %}
<form action = "/zones/add" id="addNewZoneForm1" method='post'>{% csrf_token %}
<!-- <form id="addNewSite" method='post'>{% csrf_token %} -->
<fieldset>
<table border="0" cellspacing="2" cellpadding="2" width="100%">
{{ form.as_table }}
<!-- Allow form submission with keyboard without duplicating the dialog button -->
</table>
<input type="submit" value="Submit">
</fieldset>
</form>
<script type="text/javascript">
function getSite(value){
$.ajax({
url: "sites/getinfo?siteId="+value,
type: "get",
})
}
</script>
where Print form returns :
<tr><th><label for="id_site">Site:</label></th><td><select id="id_site" name="site" onChange="getSite(this.value);">
<option value="initialValue">----Select Site----</option>
<option value="abc">ABC</option>
<option value="xyz">XYZ</option>
</select></td></tr>
<tr><th><label for="id_city">City:</label></th><td><input id="id_city" maxlength="25" name="city" type="text" value="SAN" /></td></tr>
<tr><th><label for="id_address">Address:</label></th><td><input id="id_address" maxlength="25" name="address" type="text" value="SAN" /></td></tr>
<tr><th><label for="id_state">State:</label></th><td><input id="id_state" maxlength="50" name="state" type="text" value="SAN" /></td></tr>
<tr><th><label for="id_zip">Zip:</label></th><td><input id="id_zip" maxlength="10" name="zip" type="text" value="10000001" /></td></tr>
<tr><th><label for="id_description">Description:</label></th><td><textarea cols="40" id="id_description" name="description" rows="10">
</textarea></td></tr>
We can see in the html out put that the fields have values associated but they are not rendered in the view. There is no error that I am getting, just a form with empty fields
Thanks in advance for your help
Aucun commentaire:
Enregistrer un commentaire