bigskysoftware/htmx

Suggestion: Shortcut for `hx-post` using a configurable parameter

Opened this issue · 2 comments

Hi!

I frequently use the hx-post= attribute in my projects and was wondering if it would be possible to introduce a shortcut for this parameter, such as hx=, which could be configured through JavaScript settings.

For example:

hxMainParam = "post"; // or "get", "put", ...

This would allow us to define the main method (e.g., POST or GET) globally, simplifying the use of HTMX in different contexts.

Thanks in advance!

Personal opinion: I don't really like this idea as it makes the code way harder to read imho, for what seems to bring not much value to me (except sparing 5 characters, is there any other benefit?).
On top of that, many IDEs can register non-standard attributes preferences such as htmx's ones, so most of the time you can quickly autocomplete them and not type the full hx-post by hand, which decreases even more the benefits of the idea to me.

Other than that, I'm a generally anti-htmx-inheritance guy so that's why I'm precising it's just my personal opinion! I always disable htmx's attributes inheritance as I don't want my HTML elements to randomly inherit from whatever attribute a parent defines. I like to have explicit code where you don't have to wonder depending on where the template you're looking at might be used from, what values it could inherit / carry around. And when I want inheritance (that happens!), I'll make it explicit too.

Just my 2 cents, if people support this idea, please feel free to bolster it!

A drawback that I didn't notice: sharing a code using the hx= parameter will also require providing the method of the shortcut used, making it difficult to read.