Login

Snippets by FreddieP

Snippet List

NewForms Readonly / Edit Pattern

This is a little base class that I use to display forms in a readonly mode. Providing a simple javascript on the front end to allow a user to click an **edit** link that will show/hide the actual form. To use it simply inherit from it. Then in your templates do the following: `{{ form.as_readonly_table }}` **Other Notes** * **form.html** `{% for field in bound_fields %} {% include "newforms/field.html" %} {% endfor %}` * **field.html** `{% if field.errors %} <tr> <td>&nbsp;</td> <td>{{ field.errors }}</td> </tr> {% endif %} <tr> <th style="text-align:right"> <label for="id_{{ field.name }}">{{ field.label }}{% if field.field.required %}<span class="required"><sup>*</sup></span>{% endif %}</label> </th> <td>{{ field }} {% if field.help_text %} <p class="helptext">({{ field.help_text }})</p> {% endif %} </td> </tr>`

  • template
  • newforms
  • readonly
  • edit-mode
Read More

FreddieP has posted 1 snippet.