#28387: Disabled fields should not be considered changed in bound forms
----------------------------------------+------------------------
               Reporter:  Kevin Corbin  |          Owner:  nobody
                   Type:  Bug           |         Status:  new
              Component:  Forms         |        Version:  1.11
               Severity:  Normal        |       Keywords:
           Triage Stage:  Unreviewed    |      Has patch:  0
    Needs documentation:  0             |    Needs tests:  0
Patch needs improvement:  0             |  Easy pickings:  0
                  UI/UX:  0             |
----------------------------------------+------------------------
 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:
 {{{#!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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.cea85b274964bcdf37f610a826caeb70%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to