Skip to content

Conversation

@erikgaas
Copy link
Contributor

@erikgaas erikgaas commented Dec 3, 2025

Relates to this issue in fasthtml: AnswerDotAI/fasthtml#567

Currently we suppress any attribute whose value is a 0 or an empty string. However there are legimitate use cases where these can these might exist.

For example

  • to_xml(Input(type="number", min=0, max=100))
  • to_xml(Option("select a value", value="")

The former example I think is purely a bug caused by:
v not in (False, None, '') Python evaluates 0 == False to true so this is an edge case

Meanwhile empty strings are more debatable. Google's dom manipulation strips out the empty string leaving the value which seems to be the same as setting it to True. https://stackoverflow.com/questions/14352113/setting-an-html-option-value-to-the-empty-string

It might be fair to say that we would just expect users to pass in None if they done want that attribute showing up in the final rendering.

@erikgaas erikgaas requested a review from jph00 December 3, 2025 06:19
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.

2 participants