[Django] #30014: Initialising disabled ModelChoiceField yields 'Select a valid choice'-error despite initialised option being valid

classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30014: Initialising disabled ModelChoiceField yields 'Select a valid choice'-error despite initialised option being valid

Django
#30014: Initialising disabled ModelChoiceField yields 'Select a valid choice'-error
despite initialised option being valid
-------------------------------------+-------------------------------------
     Reporter:  thoha                |                    Owner:  Etienne
                                     |  Chove
         Type:  Bug                  |                   Status:  assigned
    Component:  Forms                |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  forms, disabled      |             Triage Stage:  Accepted
  field, error, to_field_name        |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Description changed by felixxm:

Old description:

> I have a form with a ModelChoiceField that gets initialised to a specific
> value using get_initial in that form's View. This value is a valid choice
> for that Model. I don't want the user to be able to change the option on
> the form, but it needs to be displayed nonetheless.
>
> When I set disabled=True on that field in forms.py, submitting the form
> yields the following error:
>
> <ul class="errorlist"><li>fieldname<ul class="errorlist"><li>Select a
> valid choice. That choice is not one of the available
> choices.</li></ul></li></ul>.
>
> Firstly, I would like to comment on the general quality of the error
> message, as it is not very useful: It does not return ''which'' choice it
> considers invalid. Including this information would make the message much
> more informative, and would avoid sending people on a wild goose chase to
> discover what the message could possibly mean.
>
> Secondly, if a field is disabled but does contain a valid choice,
> validating the form should work and not trigger an error.
>
> Edit: Adding the **to_field_name** option to the form field fixes the
> problem. However, when disabled=True is not present, this is not
> required.
>
> This is probably related to the bugfix for this bug:
> https://code.djangoproject.com/ticket/28387
New description:

 I have a form with a ModelChoiceField that gets initialised to a specific
 value using get_initial in that form's View. This value is a valid choice
 for that Model. I don't want the user to be able to change the option on
 the form, but it needs to be displayed nonetheless.

 When I set disabled=True on that field in forms.py, submitting the form
 yields the following error:

 <ul class="errorlist"><li>fieldname<ul class="errorlist"><li>Select a
 valid choice. That choice is not one of the available
 choices.</li></ul></li></ul>.

 Firstly, I would like to comment on the general quality of the error
 message, as it is not very useful: It does not return ''which'' choice it
 considers invalid. Including this information would make the message much
 more informative, and would avoid sending people on a wild goose chase to
 discover what the message could possibly mean.

 Secondly, if a field is disabled but does contain a valid choice,
 validating the form should work and not trigger an error.

 Edit: Adding the **to_field_name** option to the form field fixes the
 problem. However, when disabled=True is not present, this is not required.

 This is probably related to the bugfix for this bug: #28387

--

--
Ticket URL: <https://code.djangoproject.com/ticket/30014#comment:20>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.cce2a4a3f6d19505b79dda71971d747d%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30014: Initialising disabled ModelChoiceField yields 'Select a valid choice'-error despite initialised option being valid

Django
In reply to this post by Django
#30014: Initialising disabled ModelChoiceField yields 'Select a valid choice'-error
despite initialised option being valid
-------------------------------------+-------------------------------------
     Reporter:  thoha                |                    Owner:  Etienne
                                     |  Chove
         Type:  Bug                  |                   Status:  assigned
    Component:  Forms                |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  forms, disabled      |             Triage Stage:  Ready for
  field, error, to_field_name        |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by felixxm):

 * stage:  Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/30014#comment:21>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.b41fe3dd798b51f8a06fa77e8627dde1%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30014: Initialising disabled ModelChoiceField yields 'Select a valid choice'-error despite initialised option being valid

Django
In reply to this post by Django
#30014: Initialising disabled ModelChoiceField yields 'Select a valid choice'-error
despite initialised option being valid
-------------------------------------+-------------------------------------
     Reporter:  thoha                |                    Owner:  Etienne
                                     |  Chove
         Type:  Bug                  |                   Status:  closed
    Component:  Forms                |                  Version:  master
     Severity:  Normal               |               Resolution:  fixed
     Keywords:  forms, disabled      |             Triage Stage:  Ready for
  field, error, to_field_name        |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"e7cdb0cd7eb5eb677af8dae7bfc6845186f861b0" e7cdb0c]:
 {{{
 #!CommitTicketReference repository=""
 revision="e7cdb0cd7eb5eb677af8dae7bfc6845186f861b0"
 Fixed #30014 -- Fixed ModelChoiceField validation when initial value is a
 model instance.

 Thanks Carlton Gibson for reviews.
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30014#comment:22>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.ac16152b731d3ade65cea88ed7f2f792%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30014: Initialising disabled ModelChoiceField yields 'Select a valid choice'-error despite initialised option being valid

Django
In reply to this post by Django
#30014: Initialising disabled ModelChoiceField yields 'Select a valid choice'-error
despite initialised option being valid
-------------------------------------+-------------------------------------
     Reporter:  thoha                |                    Owner:  Etienne
                                     |  Chove
         Type:  Bug                  |                   Status:  closed
    Component:  Forms                |                  Version:  master
     Severity:  Normal               |               Resolution:  fixed
     Keywords:  forms, disabled      |             Triage Stage:  Ready for
  field, error, to_field_name        |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

 In [changeset:"651299e1ef896210035cf9e6992b07aa02a5aac1" 651299e1]:
 {{{
 #!CommitTicketReference repository=""
 revision="651299e1ef896210035cf9e6992b07aa02a5aac1"
 [3.0.x] Fixed #30014 -- Fixed ModelChoiceField validation when initial
 value is a model instance.

 Thanks Carlton Gibson for reviews.

 Backport of e7cdb0cd7eb5eb677af8dae7bfc6845186f861b0 from master
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30014#comment:23>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/063.407af813708d94339954b612ce4b33ca%40djangoproject.com.
12