summaryrefslogtreecommitdiff
path: root/docs/topics/forms
diff options
context:
space:
mode:
authorMarc SeguĂ­ Coll <metarizard@gmail.com>2022-05-08 00:53:13 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2022-05-10 13:42:31 +0200
commit262fde94de5eb6544fc0f289575583436613c045 (patch)
treed0b5f41d41a4e4d86a2973bfb260350e4dab8c0e /docs/topics/forms
parent667105877e6723c6985399803a364848891513cc (diff)
Fixed #33622 -- Allowed customizing error messages for invalid number of forms.
Co-authored-by: Mariusz Felisiak <felisiak.mariusz@gmail.com>
Diffstat (limited to 'docs/topics/forms')
-rw-r--r--docs/topics/forms/formsets.txt20
1 files changed, 19 insertions, 1 deletions
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