#28387 closed Bug (fixed)
Disabled fields should not be considered changed in bound forms
Reported by: | Kevin Corbin | Owned by: | Srinivas Reddy Thatiparthy |
---|---|---|---|
Component: | Forms | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
This is similar to #27431, but that ticket only modified the has_changed method in the base django.forms.fields.Field class.
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:
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:
form = MyTestForm(data={}) form.is_bound #True form.has_changed() #True form.changed_data #['test_disabled']
Change History (6)
comment:1 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 7 years ago
Has patch: | set |
---|
comment:4 by , 7 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Will submit a PR soon.
Thanks,
Srini