Snippet List
Difference from standard Django 1.4 implementation is just structure of list. In django `<input>` elements are *wrapped* by their labels, and look like this::
<ul>
<li><label><input/> Label 1</label>
<li><label><input/> Label 2</label>
</ul>
This widget puts labels *after* input elements::
<ul class="form-button-radio">
<li><input/> <label>Label 1</label>
<li><input/> <label>Label 2</label>
</ul>
It makes possible to define style for both inputs and labels, hiding inputs and making labels look like pressable buttons. No javascript needed, just CSS (see docstring).
To auto-submit the form when pressing a button, JQuery can be added::
<script>
$(document).ready(function() {
$('ul.form-button-radio input[type="radio"]').change(function() {
$(this).parents('form').submit();
});
});
</script>
- widget
- label
- input
- button
- reorder
- radio
- radio button
Based on [#2020](http://djangosnippets.org/snippets/2020/)
This snippet creates a simple generic export to csv action that you can specify the fields you want exported and the labels used in the header row for each field. It expands on #2020 by using list comprehensions instead of sets so that you also control the order of the fields as well.
This template tag and suggested template allow greater control over rendering `<label>` tags for your newforms fields than using `field.label_tag`. I save the provided Python code in my app as `templatetags/forms.py` (although this name may conflict in the future).
The simplest usage:
{% label field %}
One use case is adding `class="required"` to the label tag for required fields instead of inserting markup elsewhere--this is done in the given example template.
Alternate label text and tag attributes can be passed to the inclusion tag:
{% label field "Alt. label" 'class=one,id=mylabel' %}
- templatetag
- newforms
- label
3 snippets posted so far.