#34721: ChoiceField/TypedChoiceField: .value() has inconsistent behaviour, 
coercion
not applied.
------------------------+--------------------------------------
     Reporter:  Daniel  |                    Owner:  nobody
         Type:  Bug     |                   Status:  closed
    Component:  Forms   |                  Version:  4.2
     Severity:  Normal  |               Resolution:  invalid
     Keywords:          |             Triage Stage:  Unreviewed
    Has patch:  0       |      Needs documentation:  0
  Needs tests:  0       |  Patch needs improvement:  0
Easy pickings:  0       |                    UI/UX:  0
------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 > Changing `ChoiceField(...)` to `TypedChoiceField(..., coerce=int)` does
 only affect `my_form.cleaned_data["colour"]`, but neither of
 `my_form.fields["colour"].choices`,`{{ my_form.fields.colour.choices }}`,
 or `my_form["colour"]`, or`{{ my_form.colour.value }}`.

 Yes, and that's exactly what you should use, `TypedChoiceField` and
 `cleaned_data`.

 > Ultimately leads to `{% if colour_id == my_form.colour.value %}` never
 being true when the form is bound, even when it should.

 That's an incorrect expectation. `BoundField.value()` is the ''raw'' value
 of the field.  If you're having trouble understanding how Django works,
 see TicketClosingReasons/UseSupportChannels for ways to get help.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34721#comment:5>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701896c3e3493-59ee0b0c-19a9-4925-b8a1-507db93ca03b-000000%40eu-central-1.amazonses.com.

Reply via email to