Opened 18 years ago
Closed 6 years ago
#5069 closed Uncategorized (wontfix)
newforms cannot initial SelectDateWidget 's value
| Reported by: | anonymous | Owned by: | nobody | 
|---|---|---|---|
| Component: | Uncategorized | Version: | dev | 
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no | 
| Needs tests: | no | Patch needs improvement: | no | 
| Easy pickings: | no | UI/UX: | no | 
Description
form with SelectDateWidget
class Person(newforms.form):
    birthday = forms.DateField( widget=utils.widgets.SelectDateWidget())
that 's ok
form = Person(request.POST)
but cannot
form = Person(initial = request.POST)
Change History (4)
comment:1 by , 18 years ago
comment:2 by , 18 years ago
| Resolution: | → wontfix | 
|---|---|
| Status: | new → closed | 
The problem is that:
form = Person(initial=request.POST)
doesn't pre-populate the rendered SelectDateWidget; it's left with defaults (1st of January of the earliest year in the list) instead, because the POST data is in a different format to that which initial is expected to be, and isn't passed to the widget.  There are inherent differences between initial data and bound data; the correct way to do pass in POST data is form = Person(request.POST), as you mention.
I'm closing this as wontfix, but if there's any good reason you want to pass POST data in as the inital data, reopen the ticket.
comment:3 by , 6 years ago
| Easy pickings: | unset | 
|---|---|
| Resolution: | wontfix | 
| Severity: | → Normal | 
| Status: | closed → new | 
| Type: | → Uncategorized | 
| UI/UX: | unset | 
Person(request.POST) isn't the same as Person(initial=request.POST)
If our model has two field
Code highlighting:
class Person(newforms.form): birthday = forms.DateField( widget=utils.widgets.SelectDateWidget()) name = models.CharField(max_length=80)
and we have only birthday as initial data and we want to let user fill name we will get required field error with Person(request.POST)
comment:4 by , 6 years ago
| Resolution: | → wontfix | 
|---|---|
| Status: | new → closed | 
Please see TicketClosingReasons/DontReopenTickets. 
What error do you get when you try this?