#16328: FilePathField should include blank option even when required=True
--------------------------------------+------------------------
               Reporter:  ringemup@…  |          Owner:  nobody
                   Type:  Bug         |         Status:  new
              Milestone:              |      Component:  Forms
                Version:  1.3         |       Severity:  Normal
             Resolution:              |       Keywords:
           Triage Stage:  Accepted    |      Has patch:  0
    Needs documentation:  0           |    Needs tests:  0
Patch needs improvement:  0           |  Easy pickings:  0
                  UI/UX:  1           |
--------------------------------------+------------------------
Changes (by aaugustin):

 * easy:  1 => 0
 * stage:  Unreviewed => Accepted


Comment:

 It took me a bit of time to figure out the problem; here's my analysis.

 Django's forms have an (undocumented) `empty_permitted` attribute. When
 this attribute is set to `True`, validation is short-circuited (see lines
 263-266 in django/forms/forms.py). Formsets need this internal API to
 display extra forms to add objects, but ignore them if they are submitted
 unchanged (empty). Specifically, the inlines feature of the admin uses
 this.

 However, it isn't possible to submit a formset unchanged when it contains
 a `FilePathField`. This problem may affect other fields that can't be
 submitted with an empty value, given the UI (radio buttons, drop-down
 selects), when `blank=False`. The common point of these fields is that
 their value must be chosen from a finite set defined by their `choices`
 attribute.

 In my opinion, the proper fix is to render fields as if `blank` was `True`
 when `empty_permitted` is `True`, probably by setting their
 `include_blank` attribute to `True`. Thus, the select widget for
 `FilePathField` will contain the blank choice, `BLANK_CHOICE_DASH`, as the
 first item, resolving the problem described originally.

 Unfortunately, I failed to write a patch for this because I'm not
 sufficiently familiar with the forms implementation. After searching for
 all instances of `include_blank` and `empty_permitted`, I couldn't bridge
 the gap between them. This isn't an easy picking after all :)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16328#comment:2>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to