Login

Tag "forms"

Snippet List

StaticField for non-changing text data in forms

This Field, Widget and the three lines of code in the form's clean method allow an easy (and hopefully general) way to add simple, unchangable text to a form. Example use: class OnlyTextForm(forms.ModelForm): points = StaticField(label=_('Points')) reviewer = StaticField(label=_('Reviewer')) def clean(self): for name, field in self.fields.items(): if isinstance(field, StaticField): self.cleaned_data.update({name: self.initial[name]}) return self.cleaned_data

  • forms
  • field
  • widget
Read More
Author: V
  • 1
  • 2

MultiFormWizard

This is an extended version of the FormWizard which allows display of multiple forms per step and allows usage of ModelForms with initial objects

  • multiple
  • forms
  • form
  • wizzard
  • multi-form-per-step
Read More

VAT field

VAT field with a field to select the country and a free field for the code

  • django
  • fields
  • forms
  • form
  • field
  • formfield
  • vat
  • tva
Read More

TextField

Alex Gaynor presented this idiom at EuroDjangoCon 2009.

  • forms
  • textfield
Read More

MultipleEmailsField

This is a custom field for multiple emails separated by comma. Original code was replaced by code from Django documentation: http://docs.djangoproject.com/en/dev/ref/forms/validation/ (MultiEmailField) so i'm not the author of the code, but just put it here to replace an outdated solution. Uses code from mksoft comment http://www.djangosnippets.org/snippets/1093/

  • multiple
  • forms
  • email
  • field
Read More

Debug data for forms

I sometimes find that larger forms need data associated with them, but it's a bit of a pain to retype it each time when I'm debugging. The DebugForm base class lets you specify sets of testing data that will be inserted into your form if your project is in debug mode, randomly chosen from the DEBUG_DATA dict.

  • forms
  • debug
  • defaultdata
Read More

Extended Form Wizard with ability to go backwards

This is an extended version of django wizard with the ability to go back and execute any step directly. To define next step to execute use the form field with the name "wizard_next_step". Don't forget to specify in your form the wizard_max_step field, so the knows the step number with the highest number, where the user was. An other improvement is the variable "wizard_data". It's a QueryDict with data from all wizard forms. It can be used to retrieve values from the field values of the forms from other steps. It could be helpfully for the latest step, where the user should see an overview of his input.

  • forms
  • wizard
Read More

ABN and ACN Form Fields

ACNField - Australian Company Number Form Field ABNField - Australian Business Number Form Field Any feedback / Improvements Appreciated.

  • fields
  • forms
  • abn
  • acn
Read More

Create multiple related objects at once

The following code takes two related models and creates one user interface to for create and update operations that handles them both. It enables the creation or update of instances from both models in one shot, without having to create very complex forms. As I could not find examples for creation of related objects together, I thought this might be useful for someone.

  • forms
  • object-creation
  • related-objects
Read More

DateTimeField with microseconds

Use this in your form if you want to accept input in microseconds. In a ModelForm you can override the field like this: def __init__(self, *arg, **kwargs): super(MyForm, self).__init__(*arg, **kwargs) self.fields['date'] = DateTimeWithUsecsField() *Update* May 26 2009 - Updated to address a couple issues with this approach. See http://code.djangoproject.com/ticket/9459

  • forms
  • datetimefield
  • microseconds
Read More

Readonly fields on Form/Modelform

A Form and ModelForm which provides the ability to specify certain fields as readonly, meaning that they will display their value as text wrapped with a <span> tag. The user is unable to edit them, and they are protected from POST data insertion attacks. The recommended usage is to place a NewMeta inner class on the form, with a readonly attribute which is a list or tuple of fields, similar to the fields and exclude attributes on the Meta inner class. class MyForm(ReadonlyForm): foo = forms.TextField() bar = forms.TextField() class NewMeta: readonly = ('foo',) Use these forms as you would a standard form in your templates.

  • forms
  • field
  • readonly
  • modelforms
  • span
Read More

NonceField for disabling autocompletion

For disabling autocomplete and security purpose, this snippet defines a CharField with a randomness name for each request of the form. This is useful for turning off autocomplete for credit card input in all browsers, without breaking the xhtml validation. * [https://wiki.mozilla.org/The_autocomplete_attribute_and_web_documents_using_XHTML#Security](https://wiki.mozilla.org/The_autocomplete_attribute_and_web_documents_using_XHTML#Security) * [http://en.wikipedia.org/wiki/Cryptographic_nonce](http://en.wikipedia.org/wiki/Cryptographic_nonce)

  • fields
  • forms
  • validation
  • security
  • form
  • field
  • autocomplete
  • formfield
  • nonce
Read More

141 snippets posted so far.