GithubHelp home page GithubHelp logo

formtags's Introduction

Sofokus Formtags

Installation

Formtags can be installed with setuptools. Run easy_install and include formtags in your INSTALLED_APPS list.

Alternatively, you can simply place the formtags app in your project path or copy the forms.py file to the templatetags directory of an app already in your project.

Usage

Sofokus Formtags is a tag library for Django that simplifies the task of generating customized form HTML. Think of it as a smart {% for %} tag.

To use the formtags library, include the command {% load forms %} in the template.

A trivial example:

```django
{% load forms %}
{% form form %}
{% field %}(render form field){% endfield %}
{% endform %}
```

This is equivalent to:

```django
{% for field in form %}
(render form field)
{% endforeach %}
```

Now, what if you want to change the rendering of a single field, but the built-in output is good enough for the rest? With the standard form tag, you're out of luck. With formtags, it's this easy:

```django
{% form %}
{% field "my_special_field" %}
(custom rendering)
{% endfield %}
{% field %}
( standard rendering )
{% endfield %}
{% endform %}
```

OK, but what if the field you want to change is in the middle of the form? We can use matchers:

```django
{% form %}
{% field "<my_special_field" %}
( standard rendering )
{% endfield %}
{% field "my_special_field" %}
(custom rendering)
{% endfield %}
{% field %}
( standard rendering )
{% endfield %}
{% endform %}
```

The {% field %} tag with no matcher is the catchall field that handles all the fields left over. The form is rendered in two passes, each matcher having a specific precedence. Thus this works too:

```django
{% form %}
{% field %}
( standard rendering )
{% endfield %}
{% field "my_special_field" %}
(custom rendering)
{% endfield %}
{% endform %}
```

For a full list of tags and filters included, refer to the documentation in the forms.py file.

Fixing bugs and adding features

When fixing a bug you have discovered, start by creating a unit test in tests.py that reproduces the problem. This will help you determine when the bug is truly fixed and, most importantly, guard against future regressions.

The same applies when adding a new feature. Start with the test cases, then implement the feature.

formtags's People

Contributors

callaa avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.