Skip to content

Commit

Permalink
Merge pull request #199 from plone/allowed_content_types--4.3.x
Browse files Browse the repository at this point in the history
Add support for accept attribute on file input (4.3.x branch)
  • Loading branch information
thet authored Mar 15, 2024
2 parents c05c9ba + f327f33 commit dc9ccae
Show file tree
Hide file tree
Showing 4 changed files with 31 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]
8 changes: 8 additions & 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|nothing}"
type="file"
tal:define="
is_invalid python:view.error and 'is-invalid' or '';
Expand All @@ -147,6 +148,13 @@
class string:form-control $is_invalid;
"
/>
<div class="form-text"
tal:condition="view/accept|nothing"
i18n:translate="namedfile_accepted_types"
>
Allowed types:
<tal:i18n i18n:name="accepted_types">${view/accept}</tal:i18n>.
</div>

<script type="text/javascript"
tal:condition="python:allow_nochange and action != 'replace'"
Expand Down
8 changes: 8 additions & 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|nothing}"
type="file"
tal:attributes="
id string:${view/id}-input;
Expand All @@ -149,6 +150,13 @@
maxlength view/maxlength;
"
/>
<div class="form-text"
tal:condition="view/accept|nothing"
i18n:translate="namedfile_accepted_types"
>
Allowed types:
<tal:i18n i18n:name="accepted_types">${view/accept}</tal:i18n>.
</div>

<script type="text/javascript"
tal:condition="python:allow_nochange and action != 'replace'"
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"plone.base",
"plone.app.contentlisting",
"plone.dexterity",
"plone.formwidget.namedfile>=3.1.0",
"plone.i18n",
"plone.protect",
"plone.registry",
Expand Down

0 comments on commit dc9ccae

Please sign in to comment.