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

Enhancement: Add html_params class attribute to BaseField #512

Open
hasansezertasan opened this issue Feb 21, 2024 · 1 comment
Open

Enhancement: Add html_params class attribute to BaseField #512

hasansezertasan opened this issue Feb 21, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@hasansezertasan
Copy link
Contributor

hasansezertasan commented Feb 21, 2024

Is your feature request related to a problem? Please describe.
As HTMX rises, we see many new libraries based on HTML attributes like AlpineJS and Hyperscript.

I am using HTMX, AlpineJS, and Hyperscript in my projects now and these libraries mostly rely on HTML attributes, so to use them properly I have to override each Field and add html_params class attribute.

Describe the solution you'd like
I don't know if I'm asking too much but what about adding that html_params attribute to the BaseField class and updating input_params methods?

Additional context
I believe in the end, this feature will be in demand.

@hasansezertasan hasansezertasan added the enhancement New feature or request label Feb 21, 2024
@hasansezertasan hasansezertasan changed the title Enhancement: Add extra_options class attribute to BaseField Enhancement: Add html_params class attribute to BaseField Feb 22, 2024
@hasansezertasan
Copy link
Contributor Author

hasansezertasan commented Feb 22, 2024

WDYT about this @jowilf?

I did some work on it, you can find it at hasansezertasan/starlette-admin/tree/html_params. I've been hesitating about opening PR for a while. I would be very happy if you review it and I would like to open PR if you deem it appropriate.

Also, if I pass the hyperscript attributes ({"_": "statement"}), the html_params function turns the underscores into dashes, so it's still not working for the hyperscript library.

def html_params(kwargs: Dict[str, Any]) -> str:
"""Converts a dictionary of HTML attribute name-value pairs into a string of HTML parameters."""
params = []
for k, v in kwargs.items():
if v is None or v is False:
continue
if v is True:
params.append(k)
else:
params.append('{}="{}"'.format(str(k).replace("_", "-"), escape(v)))
return " ".join(params)

Take a look at the hyperscript usage: ///_hyperscript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant