Open rixx opened 6 years ago
Hi,
I think this is nearly impossible. File input can have default value due to security reasons.
We work around this issue by making our form validated against previously submitted data.
I.e. cleaned data will be populated not only from request.POST and request.FILES but from session data too.
Hi, I am using django-formtools for 5 months now and I still have the same issue as @rixx . Do you have any workaround for this? Thanks!
Hi I suspect that the "initial" parameter of the form is not populated correctly. In the backend the file seems to be available as expected, also after multiple forward/backward jumps (I verified this with debug-prints). However, when e.g. using the FileInput widget it will not be clear in the frontend that a value has already been provided (due to the way the widget is rendered, as proofit404 said, the file input element cannot have a value).
Now, the actual problem is, that if the FileField is required it will be rendered as input element with the required attribute, and choosing a file will be required even though there is already a value assigend in the backend. The FileField will only render a required attribute if there is no initial value provided and the FileField has not gotten required=False as argument. I verified my assumptions by just changing the required argument from True to False. With this things work as expected except that the file-upload will not be enforced. Sorry for not writing a patch, I tried a few minutes but had no time to dive into the formtools code any further.
Here is the relevant code from django: https://github.com/django/django/blob/master/django/forms/widgets.py#L396
I verified my assumptions by just changing the required argument from True to False. With this things work as expected except that the file-upload will not be enforced.
I cannot approve this statement.
I have the same issue and i tested with formtools 2.5.1 and 2.4.1. When i go back a step to a form with a FileField, the FielField is empty, although i uploaded a file on the first visit of that form. And that is independent of the required attribute of the field. The required attribute only enforces an upload before one could leave the form with the FileField as it should.
One of my forms includes a working FileField. But if I upload a file to that step of the wizard, and use the "back" button to return to that step later on, the file is then not shown (but all other data is shown correctly). This is probably related to (or a version of) #23.