Reputation: 2078
I am trying to "style" a django form using jquery. Now i just started with jquery. What I want to do is cut the form into subgroups, and extend on click or depending on a choice you made in the form. (do i need ajax for this?)
For now i try to "hide" elements with a css class, and remove or add that class when needed.
html:
<form action="{% url 'item_create' %}" method="post">{% csrf_token %}
{{ item_form.as_p }}
<input type="submit" value="Submit" />
</form>
css:
.hide {display: none;}
js:
$(function(){
$('#id_flavor').addClass('hide');
});
where #id_flavor is the id for the flavor field in my form. My problem now is that it only hides the input field, and not my label and help_text. How can i achieve that it removes field+extra field parts
(a part of my rendered django form http://pastebin.com/LtKFUJaT (not sure if it helps as extra information)
Upvotes: 0
Views: 117
Reputation: 1459
In jquery you could just do something like this to hide whole input container:
$(function() {
$('#id_flavor').parents('p:first').hide();
});
Upvotes: 1