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/
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.
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" }}
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.
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.
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/).
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!
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...
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>
**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.