forms.formsets.BaseFormSet.total_error_count()

BaseFormSet.total_error_count() [source] To check how many errors there are in the formset, we can use the total_error_count method: >>> # Using the previous example >>> formset.errors [{}, {'pub_date': ['This field is required.']}] >>> len(formset.errors) 2 >>> formset.total_error_count() 1 We can also check if form data differs from the initial data (i.e. the form was sent without any data): >>> data = { ... 'form-TOTAL_FORMS': '1', ...

forms.formsets.BaseFormSet.can_order

BaseFormSet.can_order Default: False Lets you create a formset with the ability to order: >>> from django.forms import formset_factory >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory(ArticleForm, can_order=True) >>> formset = ArticleFormSet(initial=[ ... {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, ... {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, ... ]) >>> for form in fo

forms.formsets.BaseFormSet.can_delete

BaseFormSet.can_delete Default: False Lets you create a formset with the ability to select forms for deletion: >>> from django.forms import formset_factory >>> from myapp.forms import ArticleForm >>> ArticleFormSet = formset_factory(ArticleForm, can_delete=True) >>> formset = ArticleFormSet(initial=[ ... {'title': 'Article #1', 'pub_date': datetime.date(2008, 5, 10)}, ... {'title': 'Article #2', 'pub_date': datetime.date(2008, 5, 11)}, ... ]) >&

forms.formsets.BaseFormSet

class BaseFormSet [source] A formset is a layer of abstraction to work with multiple forms on the same page. It can be best compared to a data grid. Let’s say you have the following form: >>> from django import forms >>> class ArticleForm(forms.Form): ... title = forms.CharField() ... pub_date = forms.DateField() You might want to allow the user to create several articles at once. To create a formset out of an ArticleForm you would do: >>> from django.form

forms.Form.use_required_attribute

Form.use_required_attribute New in Django 1.10. When set to True (the default), required form fields will have the required HTML attribute. Formsets instantiate forms with use_required_attribute=False to avoid incorrect browser validation when adding and deleting forms from a formset.

forms.Form.required_css_class

Form.required_css_class It’s pretty common to style form rows and fields that are required or have errors. For example, you might want to present required form rows in bold and highlight errors in red. The Form class has a couple of hooks you can use to add class attributes to required rows or to rows with errors: simply set the Form.error_css_class and/or Form.required_css_class attributes: from django.forms import Form class ContactForm(Form): error_css_class = 'error' required_cs

forms.Form.prefix

Form.prefix You can put several Django forms inside one <form> tag. To give each Form its own namespace, use the prefix keyword argument: >>> mother = PersonForm(prefix="mother") >>> father = PersonForm(prefix="father") >>> print(mother.as_ul()) <li><label for="id_mother-first_name">First name:</label> <input type="text" name="mother-first_name" id="id_mother-first_name" required /></li> <li><label for="id_mother-last_na

forms.Form.order_fields()

Form.order_fields(field_order) New in Django 1.9. You may rearrange the fields any time using order_fields() with a list of field names as in field_order.

forms.Form.non_field_errors()

Form.non_field_errors() This method returns the list of errors from Form.errors that aren’t associated with a particular field. This includes ValidationErrors that are raised in Form.clean() and errors added using Form.add_error(None, "...").

forms.Form.label_suffix

Form.label_suffix A translatable string (defaults to a colon (:) in English) that will be appended after any label name when a form is rendered. It’s possible to customize that character, or omit it entirely, using the label_suffix parameter: >>> f = ContactForm(auto_id='id_for_%s', label_suffix='') >>> print(f.as_ul()) <li><label for="id_for_subject">Subject</label> <input id="id_for_subject" type="text" name="subject" maxlength="100" required /><