thomasborgen / hypermedia

Composable HTML rendering in pure python with FastAPI and HTMX in mind
MIT License
14 stars 0 forks source link

How to add for='...' to Label? #34

Closed BKFlister closed 4 weeks ago

BKFlister commented 1 month ago

What is the correct/best method to add for='...' to Label?

This will fail:

Label('Username', for='username'),
Input(id='username', name='username', type='text', placeholder='Enter your username', required=True)

This is working:

Label('Username', **{'for':'username'}),
Input(id='username', name='username', type='text', placeholder='Enter your username', required=True)

I see that FastHTML/FastTag uses fr to handle for

Label('Username', fr='username'),
Input(id='username', name='username', type='text', placeholder='Enter your username', required=True)

FastHTML/FastTag
https://www.fastht.ml

FastTag - Python library that mirrors fasttags from FastHTML/FastCore
https://github.com/adamritter/fasttag

thomasborgen commented 4 weeks ago

I'm super stoked that you are actively trying out hypermedia and making issues.

for_ should already work and be autocompleted for Label and Output elements.

Label(for_="username")

https://github.com/thomasborgen/hypermedia/blob/b291a047d8d26f23a199383eb5bace55f5b9aed4/hypermedia/types/attributes.py#L518

and

https://github.com/thomasborgen/hypermedia/blob/b291a047d8d26f23a199383eb5bace55f5b9aed4/hypermedia/types/attributes.py#L363

I think all the attributes that conflicts with keywords has a trailing _ underscore. :) ie: class_, but with class_ you can also use classes=[] instead.

BKFlister commented 4 weeks ago

Thanks,

Label("Username", for_="username")

Results in a for with a hyphen, for- ?

<label for-="username">Username:</label>

class_ result in classwithout a hyphen.

thomasborgen commented 4 weeks ago

Thanks for checking and Sorry... the Alias was not set up correctly.

thomasborgen commented 4 weeks ago

Fixed, will be released together with another issue. :)

thomasborgen commented 4 weeks ago

Fixed in 5.2.0 release :)