jazzband / jazzband/django-floppyforms

ClearableFileInput and "required" attritube at the Edit time

Open
#181 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
836
Forks
150
PR merge metrics
No merged PRs in 30d

Description

The ClearableFileInput at the edition time (when a file has already been uploaded), for files required , let the "required" attribute in the input. The consequence of this, the browser (like Chrome) didn't know a file has already been uploaded, a tooltip appears and the submission of the form is blocked.

The standard Django widget does not show the "required" attribute at any time

Django widget rendering at the creation time

``` html

```

Django widget redering at the edit time, (with file in it)

``` html
Currently: RICE.pdf
Change:
```

Floppyform widget rendering at the creation time

``` html

```

Floppyform widget rendering at the edition time, with file already uploaded

``` html

RICE.pdf

```

In the floppyform widget rendering, we clearly see the "required" attribute which does not appear on the Django widget rendering.
### Workaround

To avoid this, I rewrite the widget, get_context method actually

``` python
def get_context(self, name, value, attrs):
ctx = super(MyClearableFileInput, self).get_context(name, value, attrs)
if value:
ctx['required'] = False
return ctx
```

Contributor guide

Open the contributing guide

Research direction

Start at ClearableFileInput and its get_context method, using the reported edit-time rendering and the supplied workaround as the behavioral reference. Verify that a file-backed field does not render the required attribute while a new required upload still does; the payload names no repository file or test to run.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.