#35542: BoundField's label and help_text and renderer should be properties not
class members
-------------------------------------+-------------------------------------
     Reporter:  Christophe Henry     |                    Owner:
         Type:                       |  Christophe Henry
  Cleanup/optimization               |                   Status:  closed
    Component:  Forms                |                  Version:  dev
     Severity:  Normal               |               Resolution:
                                     |  worksforme
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Christophe Henry):

 Replying to [comment:4 Natalia Bidart]:

 > And in my template, the correct help text is shown at all times

 That's because when you do {{{ self.fields["foo_select"].help_text =
 f"Indicate {user.first_name}'s pet name" }}}, at this stage,
 [https://github.com/django/django/blob/main/django/forms/forms.py#L104
 self._bound_fields_cache] may not be populated. But if you do the
 following:

 {{{#!python
 class FooForm(forms.Form):
     foo_select = forms.CharField()
     ...  # Other fields

     def __init__(self, user, *args, **kwargs):
         super().__init__(*args, **kwargs)
         # candid dev not knowing the difference between self[] and
 self.fields[]
         # setting avariable for every field
         for field in self:
             field.should_do_something = False
         self.fields["foo_select"].help_text = f"Indicate
 {user.first_name}'s pet name"

         # demonstration
         assert self["foo_select"].help_text ==
 self.fields["foo_select"].help_text
 }}}

 Please don't tell me this is not a valid situation. This happened to me on
 a project recently and I got a hard time tracking down why this happened.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35542#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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107019091707b3d-3ed25e3f-fe3f-4556-a87b-445ba4107ede-000000%40eu-central-1.amazonses.com.

Reply via email to