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

HTMLFormElement.attributes: Allow to extend HTML attributes programmatically. #116

Merged
merged 2 commits into from
Jul 18, 2023

Conversation

thet
Copy link
Member

@thet thet commented Jul 14, 2023

Came out of necessity and the discussion at: plone/plone.app.z3cform#176

See the z3c.form.browser.widgets.rst doctest on how to use it.
Basically it allows for attribute expansion in Chameleon templates like:

<input type="text" tal:attributes="view/attributes" />

You can just set individual attributes like so:

if widget.id == "cancel":
    widget.attributes["formnovalidate"] = "formnovalidate"

There is no need to include the outdated and incomplete list of HTML attributes in the templates anymore. You can just set them via Python.

Note: This attribute expansion does only work that way in Chameleon. Therefore we cannot change any of the templates in z3c.form because - I think - it needs to stay compatible with the Zope PageTemplates reference implementation.

Copy link
Member

@gforcada gforcada left a comment

Choose a reason for hiding this comment

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

Looks great! 🤩

Is there a page on MDN where we can track the list of attributes? Though I guess it does not change that often anyway 🤞🏾

Copy link
Contributor

@petschki petschki left a comment

Choose a reason for hiding this comment

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

LGTM!

@thet
Copy link
Member Author

thet commented Jul 14, 2023

@gforcada something like this‌? https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
But I would not include any attribute validation. It's up to the developer to add correct attributes. That allows also for any data-* attributes or special non-standard JS frontend framework attributes.

src/z3c/form/browser/widget.py Outdated Show resolved Hide resolved
src/z3c/form/browser/widget.py Outdated Show resolved Hide resolved
@thet
Copy link
Member Author

thet commented Jul 17, 2023

@icemac tnx for the review! I implemented your suggestions.

Co-authored-by: Michael Howitz <icemac@gmx.net>
@icemac icemac merged commit cb3d702 into master Jul 18, 2023
12 checks passed
@icemac icemac deleted the flexible-attributes branch July 18, 2023 06:06
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.

4 participants