Skip to content

Commit

Permalink
file input: Show accepted media types.
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed Mar 15, 2024
1 parent 49d47c6 commit 57815fe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions plone/formwidget/namedfile/file_input.pt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@
maxlength view/maxlength;
"
/>
<div class="form-text"
tal:condition="view/accept"
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'"
tal:content="string:document.getElementById('${view/id}-input').disabled=true;"
Expand Down
8 changes: 8 additions & 0 deletions plone/formwidget/namedfile/image_input.pt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@
maxlength view/maxlength;
"
/>
<div class="form-text"
tal:condition="view/accept"
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'"
tal:content="string:document.getElementById('${view/id}-input').disabled=true;"
Expand Down
4 changes: 4 additions & 0 deletions plone/formwidget/namedfile/widget.rst
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ At first, there is no value, so the behaviour is much like before::
>>> print(image_widget.render())
<span id="widget.id.image" class="named-image-widget required namedimage-field" >
<input accept="image/*" type="file" id="widget.id.image-input" name="widget.name.image" />
<div class="form-text" >Allowed types: image/*.</div>
</span>


However, if we now set a value, we will have the option of keeping it,
or changing it. The filename can handle unicode and international
characters::
Expand Down Expand Up @@ -440,12 +442,14 @@ At first, there is no value, so the behaviour is much like before::
>>> print(file_widget_constrained.render())
<span id="widget.id.file" class="named-file-widget required namedfile-field" >
<input accept="audio/mp3, audio/flac, .wav" type="file" id="widget.id.file-input" name="widget.name.file" />
<div class="form-text" >Allowed types: audio/mp3, audio/flac, .wav.</div>
</span>

>>> image_widget_constrained.update()
>>> print(image_widget_constrained.render())
<span id="widget.id.image" class="named-image-widget required namedimage-field" >
<input accept="image/webp, image/png, .jpg" type="file" id="widget.id.image-input" name="widget.name.image" />
<div class="form-text" >Allowed types: image/webp, image/png, .jpg.</div>
</span>


Expand Down

0 comments on commit 57815fe

Please sign in to comment.