Skip to content

Commit

Permalink
Add support for the "accept" attribute on file inputs.
Browse files Browse the repository at this point in the history
If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: plone/plone.formwidget.namedfile#66
Depends on:
- plone/plone.namedfile#158
- plone/plone.formwidget.namedfile#67
  • Loading branch information
thet committed Mar 14, 2024
1 parent c05c9ba commit 3ec335a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
14 changes: 14 additions & 0 deletions news/198.feature
@@ -0,0 +1,14 @@
Add support for the "accept" attribute on file inputs.

If the widget's field - if there is one - has the "accept" attribute set (the
`NamedImage` field has `image/*` set by default) then this is rendered as an
`accept` attribute on the file input.

This would restrict the allowed file types before uploading while still being
checked on the server side.

Fixes: https://github.com/plone/plone.formwidget.namedfile/issues/66
Depends on:
- https://github.com/plone/plone.namedfile/pull/158
- https://github.com/plone/plone.formwidget.namedfile/pull/67
[thet]
1 change: 1 addition & 0 deletions plone/app/z3cform/templates/file_input.pt
Expand Up @@ -133,6 +133,7 @@
</tal:block>

<input class="form-control"
accept="${view/accept}"
type="file"
tal:define="
is_invalid python:view.error and 'is-invalid' or '';
Expand Down
1 change: 1 addition & 0 deletions plone/app/z3cform/templates/image_input.pt
Expand Up @@ -139,6 +139,7 @@
</tal:block>

<input class="form-control"
accept="${view/accept}"
type="file"
tal:attributes="
id string:${view/id}-input;
Expand Down

0 comments on commit 3ec335a

Please sign in to comment.