Skip to content

Commit

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

This already restricts the allowed file types before uploading while still being checked on the server side too.

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 e2943c1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions news/198.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Add support for accept attribute on file input.

If the widget's field - if there is one - has `allowedContentTypes` set (the `NamedImage` field has `image/*` set by default) the allowed content types are rendered as `accept` attribute on the file input.

This already restricts the allowed file types before uploading while still being checked on the server side too.

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
1 change: 1 addition & 0 deletions plone/app/z3cform/templates/file_input.pt
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 e2943c1

Please sign in to comment.