Login

custom css classes for newforms

Author:
robharvey
Posted:
May 14, 2007
Language:
Python
Version:
.96
Tags:
newforms css
Score:
1 (after 1 ratings)

This isn't really any trick, its just that I didn't find any documentation of this or any references in searching. There are a few changes proposed for css classes which might make this redundant, but for now this works!

If you want to add attributes for any fields, just include them in the widget constructor. They get written out in key value pairs when the input field is being created. e.g. in the example above, this will come out like: '<input type="text" name="start_date" id="id_start_date" class="vDateField required" size="10"/>'

1
2
3
4
5
6
7
8
calendar_widget = forms.widgets.TextInput(attrs={'class':"vDateField required", 'size':10})

class ERSelectForm(forms.Form):
    """
    Allow for selection of dates
    """
    start_date = forms.DateField(widget=calendar_widget)
    end_date = forms.DateField(widget=calendar_widget)

More like this

  1. Add CSS class template filter by lazerscience 4 years, 6 months ago
  2. Changing the look of newforms as_table with a custom BaseForm by bikeshedder 7 years, 11 months ago
  3. Automatic stripping textual form fields by nail.xx 6 years, 9 months ago
  4. Honeypot Field by SmileyChris 8 years, 2 months ago
  5. Radio widget with labels after inputs by avsd 2 years, 10 months ago

Comments

Please login first before commenting.