#30014: Initialising disabled ModelChoiceField yields 'Select a valid 
choice'-error
despite initialised option being valid
-------------------------------------+-------------------------------------
     Reporter:  thoha                |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Forms                |                  Version:  2.1
     Severity:  Normal               |               Resolution:
     Keywords:  forms, disabled      |             Triage Stage:
  field, error, to_field_name        |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Etienne Chove):

 Replying to [comment:8 Carlton Gibson]:
 > Hi Etienne.
 >
 > Thanks for the test case. It's not quite working as expected I think...
 >
 > I get exactly the same failure with `disabled` `True` or `False`. (i.e.
 changing it doesn't make the test pass.)
 >
 > Can you double check and adjust?
 > (I'll leave it open for the moment.)

 Hi Carlton,

 Tahnk for your analysis.

 If you write **disabled=True**, the test fails due to the bug described
 here. If you set **disabled=False**, the test fails because there're no
 data given to the form.

 Here's the code failing only for **disabled=True** :
 {{{
 from django.forms import ModelChoiceField, Form
 from django.test import TestCase

 from ..models import ChoiceOptionModel


 class ModelChoiceFieldTest(TestCase):

     def test_disabled_field_1(self):
         opt1 = ChoiceOptionModel(12345)
         opt1.save()

         class MyForm(Form):
             field = ModelChoiceField(
                 queryset=ChoiceOptionModel.objects.all(), disabled=False,
                 initial=opt1)

         self.assertTrue(MyForm({"field": str(opt1.pk)}).is_valid())
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30014#comment:9>
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/063.0ce2fb418b49642e2c5e55289f418930%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to