Other form field classes included in django.forms.fields and
django.forms.models override the base class' has_changed method, so aren't
checking for the disabled attribute when determining whether or not a
bound form field's data has changed.
As of Django 1.11.3, the following are affected:
*django.forms.fields.BooleanField
*django.forms.fields.MultipleChoiceField
*django.forms.fields.MultiValueField
*django.forms.fields.FileField
*django.forms.models.ModelChoiceField
*django.forms.models.ModelMultipleChoiceField
Here is an example form class that exhibits this behavior:
{{{#!python
from django.contrib.auth import get_user_model
class MyTestForm(forms.Form):
test_disabled = forms.ModelChoiceField(disabled=True,
queryset=get_user_model().objects.all(),
initial=get_user_model().objects.first().id)
}}}
From the console I show the bug as such:
{{{#!python
form = MyTestForm(data={})
form.is_bound #True
form.has_changed() #True
form.changed_data #['test_disabled']
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28387>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* owner: nobody => Srinivas Reddy Thatiparthy
* status: new => assigned
Comment:
Will submit a PR soon.
Thanks,
Srini
--
Ticket URL: <https://code.djangoproject.com/ticket/28387#comment:1>
Comment (by Srinivas Reddy Thatiparthy):
PR has been raised here https://github.com/django/django/pull/8761
--
Ticket URL: <https://code.djangoproject.com/ticket/28387#comment:2>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/28387#comment:3>
* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/28387#comment:4>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"5debbdfcc84266703191e084914998e38f5f52eb" 5debbdfc]:
{{{
#!CommitTicketReference repository=""
revision="5debbdfcc84266703191e084914998e38f5f52eb"
Fixed #28387 -- Fixed has_changed() for disabled form fields that subclass
it.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28387#comment:5>
Comment (by Tim Graham <timograham@…>):
In [changeset:"a3b5df8ed503ea559d2ffaca7ec0c735d98f1a38" a3b5df8]:
{{{
#!CommitTicketReference repository=""
revision="a3b5df8ed503ea559d2ffaca7ec0c735d98f1a38"
[1.11.x] Fixed #28387 -- Fixed has_changed() for disabled form fields that
subclass it.
Backport of 5debbdfcc84266703191e084914998e38f5f52eb from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28387#comment:6>