Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for accept attribute on file input. #200

Merged
merged 9 commits into from
Mar 15, 2024
Merged

Conversation

thet
Copy link
Member

@thet thet commented Mar 14, 2024

If the widget's field - if there is one - has set (the field has set by default) the allowed content types are rendered as 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 Depeds on:

@mister-roboto
Copy link

@thet thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@thet thet force-pushed the allowed_content_types branch 2 times, most recently from b13181e to f603259 Compare March 14, 2024 20:21
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
@thet
Copy link
Member Author

thet commented Mar 15, 2024

@jenkins-plone-org please run jobs

Copy link
Member

@mauritsvanrees mauritsvanrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it out and it works in combination with the other PRs.

I have added suggestions to add |nothing so it does not break when this code is used in combination with a field/widget that does not have an accept attribute. Maybe someone is using this on a field that we do not expect.

With those |nothing added, the input still works when I try it with an old release of plone.formwidget.namedfile.

plone/app/z3cform/templates/file_input.pt Outdated Show resolved Hide resolved
plone/app/z3cform/templates/file_input.pt Outdated Show resolved Hide resolved
plone/app/z3cform/templates/image_input.pt Outdated Show resolved Hide resolved
plone/app/z3cform/templates/image_input.pt Outdated Show resolved Hide resolved
@mauritsvanrees
Copy link
Member

I have released a new plone.formwidgets.namedfile and depend on it. It is up in the constraints on dist.plone.org. Tests pass now.

But the dependencies check fails. Should have nothing to do with this PR. I am on it, trying an update with plone/meta.

z3c.dependencychecker says this dependency is not needed, but it is wrong:
it is used in widgets.zcml.
@mauritsvanrees
Copy link
Member

All GitHub Actions pass. Now try Jenkins again:

@jenkins-plone-org please run jobs

@thet thet merged commit f081ed7 into master Mar 15, 2024
11 checks passed
@thet thet deleted the allowed_content_types branch March 15, 2024 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing support to constrain allowed content types.
3 participants