Login

Tag "formfield"

Snippet List

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

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

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

3 snippets posted so far.