diff options
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/releases/4.1.txt | 5 | ||||
| -rw-r--r-- | docs/topics/forms/formsets.txt | 20 |
2 files changed, 24 insertions, 1 deletions
diff --git a/docs/releases/4.1.txt b/docs/releases/4.1.txt index fa5990393b..a9e6d71cd1 100644 --- a/docs/releases/4.1.txt +++ b/docs/releases/4.1.txt @@ -292,6 +292,11 @@ Forms attributes help to identify widgets where its inputs should be grouped in a ``<fieldset>`` with a ``<legend>``. +* The :ref:`formsets-error-messages` argument for + :class:`~django.forms.formsets.BaseFormSet` now allows customizing + error messages for invalid number of forms by passing ``'too_few_forms'`` + and ``'too_many_forms'`` keys. + Generic Views ~~~~~~~~~~~~~ diff --git a/docs/topics/forms/formsets.txt b/docs/topics/forms/formsets.txt index 1b54f2accb..c0f6df0855 100644 --- a/docs/topics/forms/formsets.txt +++ b/docs/topics/forms/formsets.txt @@ -287,12 +287,20 @@ sure you understand what they do before doing so. a form instance with a prefix of ``__prefix__`` for easier use in dynamic forms with JavaScript. +.. _formsets-error-messages: + ``error_messages`` ------------------ The ``error_messages`` argument lets you override the default messages that the formset will raise. Pass in a dictionary with keys matching the error messages -you want to override. For example, here is the default error message when the +you want to override. Error message keys include ``'too_few_forms'``, +``'too_many_forms'``, and ``'missing_management_form'``. The +``'too_few_forms'`` and ``'too_many_forms'`` error messages may contain +``%(num)d``, which will be replaced with ``min_num`` and ``max_num``, +respectively. + +For example, here is the default error message when the management form is missing:: >>> formset = ArticleFormSet({}) @@ -309,6 +317,10 @@ And here is a custom error message:: >>> formset.non_form_errors() ['Sorry, something went wrong.'] +.. versionchanged:: 4.1 + + The ``'too_few_forms'`` and ``'too_many_forms'`` keys were added. + Custom formset validation ------------------------- @@ -410,6 +422,9 @@ deletion, is less than or equal to ``max_num``. ``max_num`` was exceeded because the amount of initial data supplied was excessive. +The error message can be customized by passing the ``'too_many_forms'`` message +to the :ref:`formsets-error-messages` argument. + .. note:: Regardless of ``validate_max``, if the number of forms in a data set @@ -446,6 +461,9 @@ deletion, is greater than or equal to ``min_num``. >>> formset.non_form_errors() ['Please submit at least 3 forms.'] +The error message can be customized by passing the ``'too_few_forms'`` message +to the :ref:`formsets-error-messages` argument. + .. note:: Regardless of ``validate_min``, if a formset contains no data, then |
