Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClearableFileInput and "required" attritube at the Edit time #181

Open
moumoutte opened this issue Oct 4, 2016 · 1 comment
Open

ClearableFileInput and "required" attritube at the Edit time #181

moumoutte opened this issue Oct 4, 2016 · 1 comment

Comments

@moumoutte
Copy link

moumoutte commented Oct 4, 2016

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

<input id="id_file" name="file" type="file">

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

   Currently: <a href="/my/file/931/">RICE.pdf</a> <br>Change: <input id="id_file" name="file" type="file">

Floppyform widget rendering at the creation time

<input type="file" name="file" required="" id="id_file" class="form-control">

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

<a target="blank" href="/my/file/931/">
 <span class="fa fa-file"> RICE.pdf </span>
</a>
<Change:

<input type="file" name="file" required="" id="id_file" class="form-control">

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

     def get_context(self, name, value, attrs):
            ctx = super(MyClearableFileInput, self).get_context(name, value, attrs)
            if value:
                ctx['required'] = False
           return ctx
@michaelhjulskov
Copy link

I have simular issue with ImageField
#199

Do you think your "def get_context()" code can help me?

I've been thinking maybe to solve it using a jquery hack onload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants