#28620: Loop on boundfields at init of inline sub-forms breaks the form set
-------------------------------------+-------------------------------------
     Reporter:  Jonathan Rossel      |                    Owner:
                                     |  DmitriySelischev
         Type:  Bug                  |                   Status:  assigned
    Component:  Forms                |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  inlineformset        |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Jonathan Rossel):

 Replying to [comment:3 Tim Graham]:
 > I don't think I've every seen a need to iterate over bound fields in
 `__init__()` -- certainly that's not a documented pattern. Can you instead
 make your modifications using  `self.fields['field_name'].widget` in
 `Form.__init__()`?

 Hi,

 Thanks for the hint! It does work nicely when accessing `.widget` from
 `fields['field_name']` instead of passing by the bound field. I guess it
 must come from a difference in the modification location in the
 initialization sequence (?). After re-reading the docs, I still don't
 grasp the exact difference between fields and bound fields though, and why
 what I've done should go against a documented pattern. The only things
 I've found are:
 * "''If you want to make one widget instance look different from another,
 you will need to specify additional attributes at the time when the widget
 object is instantiated and assigned to a form field (and perhaps add some
 rules to your CSS files)''."
 [https://docs.djangoproject.com/en/1.11/ref/forms/widgets/#styling-widget-
 instances]. That does not say "but before the bound field is instanciated"
 * "''If you want to provide some additional classes in addition to the
 error and required classes that may be required, you can provide those
 classes as an argument (of the BoundField instance **css_classes**
 method)''." [https://docs.djangoproject.com/en/1.11/ref/forms/api
 /#methods-of-boundfield]. That was probably what led me to this loop on
 bound fields...

 At this point, I am not sure if this ticket should stay as a bug or should
 be converted to a request for documentation improvement (possibly combined
 with a modification of the code to raise an exception if someone does what
 I did).

 Anyway, thanks for the help !

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28620#comment:4>
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/066.0f9a54dcac001127cb63c70dcec26a3f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to