GithubHelp home page GithubHelp logo

django-goodforms's Introduction

Build Status

Good forms for Django

GoodForms — rails-like renderer for your form fields. Provide fully control of filed styles and attributes. It's not replacement for django.forms.

Installation

Run pip install django-goodforms and add goodforms to INSTALLED_APPS. That's all.

Usage

The view:

from django.shortcuts import render
from django import forms

class LoginForm(forms.Form):
    username = forms.CharField()
    password = forms.PasswordField()

def sign_up(request):
    from = MyForm(initial={'username': 'johnsmith'})
    return render(request, 'index.html', {'form': form})

The template:

{% load form_fields %}

{% form name="login" class="login-form" %}
    {% textfield form.username class="login-form_input" %}
    {% textfield form.password class="login-form_input" %}
    {% submit_button "Login" %}
{% endform %}

Controls

Form tag

  • Form tag automatically inject csrf-token.
  • Fields use name attribute as prefix for id and for in labels.
{% form name="myform" action="url_or_route_name" multipart=True %}
    <!-- Form content -->
{% endform %}

Textfield and Textarea

{% textfield form.title **kwargs %}
{% textarea form.description **kwargs %}

Select

{% select form.country values="ru:Russia,de:Germany" %}

You can use any dict, iterable collection or queryset as values list:

{% select form.county values=any_iterable_object value_key="code" label_key="title" %}

Checkbox and radio-button

{% radio form.gender value="female" %}
{% radio form.gender value="male" %}

The label attribute wraps checkbox to <label> tag. All attributes provite to it:

{% checkbox form.agree label="I agree" style="font-weight: bold;" %}

<label style="font-weight: bold;">
    <input type="checkbox" name="agree" value="1"> <span>I agree</span>
</label>

Submit button

{% submit_button "Send message" %}
{% submit_button "Save as draft" name="is_draft" value=True %}

Tips

You can use any of field without a form class:

{% input "username" required=True %}
{% select "city" values="1:New York, 2:London" %}

Settigns

GOODFORMS_XHTML — Enable or disable XHTML syntax (default: False)

GOODFORMS_AUTO_ID — Automatically generate id and for attributes for fields and labels (default: True)

GOODFORMS_ID_PREFIX — Prefix for auto-generated id and for attributes. For forms without name attribute (default: field)

License

Licensed under the MIT license.

django-goodforms's People

Contributors

maxpoletaev avatar mkozmin avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

alexmon1989

django-goodforms's Issues

Get from name form class

{% from my_form %}
    {% textfield my_form.password %}
    <!-- input id="myform_password" ... -->
{% endform %}

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.