I've got an app that wants a file upload and some other attributes.   
If the user fills in the file but has problems with the other  
attributes, it should re-present the form with the attributes filled  
with his values, including the name of the file that he selects. In  
use the example below doesn't re-populate the file upload widget.  Is  
this possible?

> class FileDemoForm(forms.Form):
>     """Require another field so we can show populated file0 not  
> being bound"""
>     file0   = forms.FileField()
>     another = forms.CharField()
>
> def file_demo(request):
>     """The bound form is *not* populated with request.FILES info for  
> file0"""
>     if request.method == "POST":
>         form = FileDemoForm(request.POST, request.FILES)
>         print >> stderr, "### file_demo incoming bound POST form=\n 
> %s" % (form,)
>         if form.is_valid():
>             return HttpResponseRedirect("/")
>     else:
>         form = FileDemoForm()
>     print >> stderr, "### file_demo returning form=\n%s" % (form,)
>     return render_to_response('filedrop/file_create.html', {'form':  
> form})

The incoming form bound with request.FILES and request.POST doesn't  
show any filename in the widget:

> ### file_demo incoming bound POST form=
> <tr><th><label for="id_file0">File0:</label></th><td><input  
> type="file" name="file0" id="id_file0" /></td></tr>
> <tr><th><label for="id_another">Another:</label></th><td><ul  
> class="errorlist"><li>This field is required.</li></ul><input  
> type="text" name="another" id="id_another" /></td></tr>

The W3C spec suggests that <input type="file"> should be able to take  
a "defaultValue" or "value" attributes but I can't make that work even  
with hand-written HTML outside of Django.  It also suggests browsers  
should allow multiple file selection in their input widgets but I've  
not seen this implemented before.

So is it possible to re-populate a 'file' input widget with the user's  
selection on a failed form?

Thanks.




--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to