'Django:any way to remove this clear field?
Is there any way I can remove this model form file field's 'clear' checkbox?.I know that I can define the 'custom' widget for file field but how to address this checkbox in that?
Solution 1:[1]
Adding to @schacki's answer. Here's how to use the simpler FileInput widget:
# forms.py
from django.forms.widgets import FileInput
class SomeForm(forms.Form):
foofile = forms.FileField(widget=FileInput)
The default FileField widget seems to be ClearableFileInput.
Solution 2:[2]
I know this question is quite long, but for anyone still trying to remove the clear checkbox from displaying on form just remove blank=True from the model.
i.e.
models
myimage = models.Image(blank=True, upload_to='my_profile')
To
myimage = models.Image(upload_to='my_profile')
This is because the blank=True is what makes the checkbox to appear besides the image input in forms.
Hope this helps
Solution 3:[3]
If you are rendering the ImageField in your template using directly the typical {{ imagefieldname }} you can easily format it just substituting it by a copy-paste of the HTML generated by Django after rendering the template.
You can see that "Clear" checkbox in the HTML generated by Django and delete it if you want.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Banjer |
| Solution 2 | Micheal N.D |
| Solution 3 | yprez |
