summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2014-08-05 08:40:27 -0400
committerTim Graham <timograham@gmail.com>2014-08-05 08:49:38 -0400
commit5fdfa2d9b49cfb31298d75ffc51800e730bf876c (patch)
tree4a57656e19710b7058e45345384ce67f000b2840
parent4121ce3dfacbad0e67f204a25abf1756cbc7088f (diff)
[1.6.x] Fixed #21792 -- Documented Form.has_changed()
Thanks bjb at credil.org for the suggestion and Ivan Mesic for the draft patch. Backport of edcc75e5ac from master
-rw-r--r--docs/ref/forms/api.txt25
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/ref/forms/api.txt b/docs/ref/forms/api.txt
index 5ade678e95..8fa2de8db1 100644
--- a/docs/ref/forms/api.txt
+++ b/docs/ref/forms/api.txt
@@ -165,6 +165,31 @@ precedence::
<tr><th>Url:</th><td><input type="url" name="url" /></td></tr>
<tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
+Checking if form data has changed
+---------------------------------
+
+.. method:: Form.has_changed()
+
+Use the ``has_changed()`` method on your ``Form`` when you need to check if the
+form data has been changed from the initial data.
+
+ >>> data = {'subject': 'hello',
+ ... 'message': 'Hi there',
+ ... 'sender': 'foo@example.com',
+ ... 'cc_myself': True}
+ >>> f = ContactForm(initial=data)
+ >>> f.has_changed()
+ False
+
+When the form is submitted, we reconstruct it and provide the original data
+so that the comparison can be done:
+
+ >>> f = ContactForm(request.POST, initial=data)
+ >>> f.has_changed()
+
+``has_changed()`` will be ``True`` if the data from ``request.POST`` differs
+from what was provided in :attr:`~Form.initial` or ``False`` otherwise.
+
Accessing the fields from the form
----------------------------------