Login

Tag "checkbox"

Snippet List

CheckboxMultiSelect with interable checkboxes

A widget for a checkbox multi select, adapted from the RadioSelect widget, which allows you to iterate over each choice in the template rather than outputting the whole thing as a ul in one go. {{ form.field.label_tag }} {% for option in form.field %} <span>{{ option }}</span> {% endfor %}

  • checkbox
  • forms
  • widget
Read More

MultiSelectField with comma separated values (Field + FormField)

Daniel Roseman's snippet, updated will all fixes mentioned in the comments of the first version + some other things to make it work under Django 1.4. South, and dumpdata are working. There's an ugly int(....) at the validate function in order to cast each value as an integer before comparing it to default choices : I needed this, but if you're storing strings values, just remove the int(......) wrapper. ------------------------------------- Orginal readme Usually you want to store multiple choices as a manytomany link to another table. Sometimes however it is useful to store them in the model itself. This field implements a model field and an accompanying formfield to store multiple choices as a comma-separated list of values, using the normal CHOICES attribute. You'll need to set maxlength long enough to cope with the maximum number of choices, plus a comma for each. The normal get_FOO_display() method returns a comma-delimited string of the expanded values of the selected choices. The formfield takes an optional max_choices parameter to validate a maximum number of choices.

  • checkbox
  • multiple
  • forms
  • model
  • field
  • comma
Read More

CheckboxSelectMultiple that renders in columns

This is a CheckboxSelectMultiple widget that will render its choices divided evenly into multiple ul elements that can be styled nicely into columns. Pass in a css class to the constructor to be assigned to the ul's. See also: http://code.djangoproject.com/ticket/9230

  • checkbox
  • columns
Read More

Checkbox or radio iterator as template filter

This snippet is based on [Bill Freeman's MultiSelect checkbox iterator template filter](http://djangosnippets.org/snippets/2151/). Usage: See docstring

  • checkbox
  • choice
  • templatefilter
  • iterator
  • checkbox-input
  • form-choice
  • radio-button
  • radio-input
Read More

CheckedField

Here's a snippet to pair an arbitrary form Field type (the "target field") with a checkbox. If the checkbox is not selected, the cleaned_data value for the field will be None. If the checkbox is selected, it will return the target field's cleaned value.

  • checkbox
  • forms
  • combining
Read More

AgreementField

Creating new field to handle checkbox validation in situations where the checkbox must be checked, as in check to agree to terms and such. Thanks to Daniel Pope for the [suggestion](http://code.djangoproject.com/ticket/5957#comment:7) on Django Trac Ticket #[5957](http://code.djangoproject.com/ticket/5957)

  • newforms
  • checkbox
  • forms
  • validation
  • clean
  • booleanfield
  • agreement
Read More

Select multiple using a manytomany checkbox

Usage: from yourapp.fields import CheckBoxManyToMany from django.db import models class Weekday(models.Model): name = models.CharField() def __unicode__(self): return self.name class EventWithWeekday(models.Model): weekdays = CheckBoxManyToMany(Weekday)

  • checkbox
  • multiple
  • oldforms
  • select
Read More

MultipleChoiceCommaField

MultipleChoiceCommaField - CheckboxSelectMultiple value sequence as a single string, comma-separated. Since I frequently want to store multiple-selected choice items as a single field in the model, I found it convenient to write a custom field class. The code uses the comma as a separator, but it could be easily generalized to use any delimiter.

  • newforms
  • checkbox
  • multiple
  • choice
  • selection
Read More

8 snippets posted so far.