When a form containing a ClearableFileInput is re-rendered (e.g. due to validation error of some other field), and the clear checkbox was checked on the first submit, the widget is rendered without initial value, as empty file input.
For instance, let's says there's a model with ImageField and all the form/view mechanics to edit the model. You edit a model instance that has an uploaded image already:
1. on initial render, the field is rendered with the clear checkbox and link to existing file
2. submit the form with some invalid data (e.g. there's another field in the form that does not validate)
3. on re-render, the field is rendered as empty file input, without clear checkbox and link
AFAICS, this is because:
- ClearableFileInput.value_from_datadict() returns False
- FileField.bound_data() returns False: it only returns initial data if submitted data is None or FILE_INPUT_CONTRADICTION
- BoundField.value() returns False
- BoundField.as_widget() renders field with value set to False
I find it non-intuitive that the field is re-rendered as blank, as if there was no initial data. Is this the intended behavior? Or am I missing something?
Michael.