zio / zio-http

A next-generation Scala framework for building scalable, correct, and efficient HTTP clients and servers
https://zio.dev/zio-http
Apache License 2.0
787 stars 396 forks source link

HTML Templates can't emit attributes without values #2963

Closed drue closed 2 months ago

drue commented 2 months ago

Describe the bug Some HTML attributes, e.g. required on inputs, are boolean and do not have a value and should be rendered without an equals sign or value like this: <input name="email" required>

see: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/required

In Zio HTTP Templates, however, the required attribute is the same as all of the other attributes and takes a string value so it always emits an equals and quotes: <input name="email" required=""> which doesn't work in the browser I tried.

There are probably other HTML attributes like this and I know some popular front end libs/frameworks rely on these types of boolean attributes.

In Scalatags an empty string will render the attribute without equals or the value so maybe thats how you want to fix this, it certainly the easiest way to do so.

To Reproduce render a template like input(nameAttr:="email", requiredAttr:="")

Expected behaviour output <input name="email" required>

jdegoes commented 2 months ago

/bounty $150

cc @jgoday if you want to claim the bounty.

algora-pbc[bot] commented 2 months ago

💎 $150 bounty • ZIO

Steps to solve:

  1. Start working: Comment /attempt #2963 with your implementation plan
  2. Submit work: Create a pull request including /claim #2963 in the PR body to claim the bounty
  3. Receive payment: 100% of the bounty is received 2-5 days post-reward. Make sure you are eligible for payouts

Thank you for contributing to zio/zio-http!

Add a bounty • Share on socials

Attempt Started (GMT+0) Solution
🟢 @jgoday Jul 30, 2024, 7:35:58 PM #2973
jgoday commented 2 months ago

/attempt #2963

Added PartialBooleanAttribute, so we can use boolean attributes without specifying a value (optionally).

input(typeAttr := "text", requiredAttr)
input(typeAttr := "text", requiredAttr := false)
algora-pbc[bot] commented 2 months ago

💡 @jgoday submitted a pull request that claims the bounty. You can visit your bounty board to reward.

algora-pbc[bot] commented 2 months ago

@jgoday: You've been awarded a $150 bounty by ZIO! 👉 Complete your Algora onboarding to collect the bounty.