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 8db2761 commit c52dd4e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions news/198.feature
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@

<input class="form-control ${python:view.error and 'is-invalid' or ''}"
id="${view/id}-input"
accept="${view/accept}"
disabled="${view/disabled}"
maxlength="${view/maxlength}"
name="${view/name}"
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 @@ -94,6 +94,7 @@

<input class="form-control ${python:view.error and 'is-invalid' or ''}"
id="${view/id}-input"
accept="${view/accept}"
disabled="${view/disabled}"
maxlength="${view/maxlength}"
name="${view/name}"
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
"plone.app.textfield>=1.3.6",
"plone.base",
"plone.app.contentlisting",
"plone.formwidget.namedfile>3.0.3",
"plone.i18n",
"plone.protect",
"plone.registry",
Expand Down

0 comments on commit c52dd4e

Please sign in to comment.