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

Some empty attributes are done wrong #119

Closed
mauritsvanrees opened this issue Mar 22, 2023 · 5 comments
Closed

Some empty attributes are done wrong #119

mauritsvanrees opened this issue Mar 22, 2023 · 5 comments

Comments

@mauritsvanrees
Copy link
Member

See plone/plone.app.z3cform#162 (comment)

@ale-rt
Copy link
Member

ale-rt commented Mar 24, 2023

Uhm, zpretty has a list of boolean attributes:

_known_boolean_attributes = (
"allowfullscreen",
"allowpaymentrequest",
"async",
"autofocus",
"autoplay",
"checked",
"controls",
"default",
"disabled",
"formnovalidate",
"hidden",
"ismap",
"itemscope",
"loop",
"multiple",
"muted",
"nomodule",
"novalidate",
"open",
"playsinline",
"readonly",
"required",
"reversed",
"selected",
"truespeed",
)

I think that the expected behavior is to remove the boolean attribute if the value is empty.

@thet
Copy link
Member

thet commented Mar 27, 2023

Boolean attributes are true when they are present, regardless of their value. But it should be ok to remove the asignment part, like in maurits example.
Also see: https://developer.mozilla.org/en-US/docs/Glossary/Boolean/HTML

@ale-rt
Copy link
Member

ale-rt commented Mar 27, 2023

Yeah, I have been thinking as well about this.
I am kind of prone to close this as won't fix.
I still have no clear idea on what caused the test failure in plone/plone.app.z3cform#162.
I kind of like to have boolean attributes to be rendered valueless.

@mauritsvanrees
Copy link
Member Author

So I guess if you have this in your template, the template works fine:

disabled=""
tal:attributes="disabled python:True"

But then zpretty changes it to this:

disabled
tal:attributes="disabled python:True"

And then zope.pagetemplate or Chameleon or whatever somehow does not know how to apply the tal:attributes anymore. Can that be it? That is my working theory now.

That is not nice, but not really sure where to fix this in code. And it can easily be fixed in the template itself: there is no need to have either disabled or disable="" or disabled="disabled" in there if you are going to replace it with tal:attributes anyway.

I guess it is fine to close this issue.

@ale-rt
Copy link
Member

ale-rt commented Mar 28, 2023

It seems to me that chameleon does not behave properly with boolean attributes:

[ale@flo chameleon]$ cat test.pt
<input required="" tal:attributes="required string:required">
<input required tal:attributes="required string:required">
<input required foo="bar" tal:attributes="required string:required">

[ale@flo chameleon]$ cat test.py
from chameleon import PageTemplate

with open("test.pt") as f:
    print(PageTemplate(f.read())())

[ale@flo chameleon]$ python test.py 
<input required="required">
<input requiredrequired>
<input requiredrequired foo="bar">

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

No branches or pull requests

3 participants