Login

Tag "form"

Snippet List

UKPhoneNumberField GB v2

Validates and cleans UK telephone numbers. Number length is checked, and numbers are cleaned into a common format. For example, "+44 (0)1234 567890" will be stored as "01234 567890" Can reject premium numbers (0912 312 3123) or service numbers (1471, 118 118) with UKPhoneNumberField(reject=('premium', 'service')) Corrects the errors found in http://djangosnippets.org/snippets/1207/

  • form
  • field
  • uk
  • localflavor
  • form_field
  • model_field
  • telephone
  • gb
  • area-code
Read More

DisableableSelectWidget

A Select widget that allows choices to be disabled. Specify `disabled_choices` to indicate which choices should be present in the list, but disabled. A possible use case for this is a form that displays data that can be edited by privileged user's but only viewed by others.

  • form
  • select
  • widget
Read More

Custom CSS class in Form with template tag filter

It was based in: http://djangosnippets.org/snippets/1586/ Instead of doing this: 'attribute_name = forms.CharField(widget=forms.TextInput(attrs={'class':'special'}))` You can do this in your template: {{ form|cssclass:"attribute_name:special_class"|cssclass:"other_attribute:special_class" }}

  • filter
  • templatetag
  • css
  • form
  • class
Read More

Password Validation - Require Letters and Numbers - no regex

Simple password validation for user registration - requires that password be 7 or more characters and contain both letters and numbers. Original validation with regex approach developed by kurtis. Optimized no-regex version based on code from watchedman ran as fast or significantly faster on all systems on which we tested it.

  • registration
  • model
  • regex
  • user
  • validation
  • form
  • password
Read More

Dynamically add css-classes to formfields

This example assumes you have a form and want to highlight one of two fields by setting <class="highlight"> in the html dynamically. This is an alternative to <https://docs.djangoproject.com/en/1.3/ref/forms/widgets/#customizing-widget-instances>, but now you're not limited to assigning the class to the fields html-output, instead you can also assign it to a div around the field like done here. After assigning a css-attribute to a field, we access the css via a templatefilter *{{ field|css }}* that looks up *field.form.fields[field.name].css* and not simply *field.css*, since the latter would try to access a non-existing css-attribute on a BoundField-instance EDIT: The templatefilter is unnecessary. There is a much easier way, since the original field itself is an attribute of the BoundField named 'field'. So in the template, we can access the css via {{ field.field.css }}. Thanks to Tom Evans for pointing me at this.

  • css
  • form
  • class
  • dynamic-form
  • formfield
  • dynamic-css
  • css-class
Read More

A Django form field that accepts an uploaded image and creates a resized image attached with a push-pin

PushPinImageField is a Django form field that is a sub-class of an ImageField. The field accepts an image to upload and based on certain settings, notably the size of the resulting image, the sizes and colors of 3 different borders, as well as the color of the push pin, a re-sized image is created with a colorized push pin in the top-center. A live demo of the field as well as more detailed usage instructions are available as a [blog entry](http://www.robmisio.com/blog/2/).

  • django
  • image
  • thumbnail
  • form
  • field
  • custom-field
Read More

AjaxForm Base Classes

These base form classes add a method to return error messages as HTML encoded as JSON from Django, optionally passing in an argument to strip tags out. The method can be called in your view after checking that your form is valid. There is a ModelForm and Form class to use depending on your needs. The sample jQuery function will take the errors returned as json, loop over the errors and insert the error after each field. If you're using a form prefix, you'll need to add a hidden field to hold the value for the prefix. The `__all__` error(s), which are not bound to a field are appended to the end of the form, which you could easily reposition. Happy coding!

  • ajax
  • json
  • form
Read More

Jcrop Form

Implements a Django form that integrates image uploading plus cropping using the awesome Jcrop plugin (http://deepliquid.com/content/Jcrop.html). NOTE: Still lacks proper error handling...

  • image
  • jquery
  • form
  • jcrop
Read More

load m2m fields objects

I have a ModelForm which includes m2m field to images. User can upload images and crop them with my cool jquery cropper, then areas are saved as images and their IDs and thumbnail URLs are passed back to page and included as thumbnails with hidden inputs. I have no problem while form have no errors, and when it does, i can not just simply display thumbnails — all I have is IDs, and form has no objects to iterate cause instance was not saved, and as it was not save it has no id and as it has no id it can not have m2m relations. So i wrote templatetag which returns queryset based on ids. It works like that: <ul id="lot-images" class="thumb-uploaders"> {% if form.errors %} {% load load_form_objects %} {% load_form_objects lot_form.images as images %} {% for image in images %} {% if image %} <li> <input type="hidden" name="images" value="{{image.id}}"/> <div class="image"> <div class="mask"></div> <img src="{{ image.get_thumbnail_url }}" alt=""/> <a href="#" class="delete">Удалить</a> </div> </li> {% else %} <li><a class="upload-medium"></a></li> {% endif %} {% endfor %} {% else %} <li><a class="upload-medium"></a></li> <li><a class="upload-medium"></a></li> <li><a class="upload-medium"></a></li> <li><a class="upload-medium"></a></li> <li><a class="upload-medium"></a></li> {% endif %} </ul>

  • m2m
  • form
  • errors
Read More

FieldStack - easy form template rendering

FieldStack simplifies forms template rendering. This is enhanced version of snippet [1786](http://djangosnippets.org/snippets/1786/)

  • template
  • fields
  • forms
  • templates
  • fieldset
  • form
  • object
  • field
  • lazy
  • fieldsets
  • groups
  • stacked
  • descriptor
Read More

Easier prefix handling for forms

**autoprefixed** is a decorator for Form classes that simplifies prefix handling by storing it in a hidden field. Thus when the form is posted, the prefix can be extracted from the posted data instead of having to pass it explicitly when instantiating the form.

  • form
  • prefix
Read More

99 snippets posted so far.