-
-
Notifications
You must be signed in to change notification settings - Fork 218
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
Add HTMX and Alpine.js alongside helpful utilities, common js_entry point #35224
Conversation
…alpine to get going quickly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments from today's product team code review. Makes sense on the whole, noting I (and other devs probably) will need to read through htmx and alpine docs for some particulars.
corehq/apps/hqwebapp/static/hqwebapp/js/htmx_utils/hq_hx_action.js
Outdated
Show resolved
Hide resolved
corehq/apps/hqwebapp/static/hqwebapp/js/htmx_utils/retry_request.js
Outdated
Show resolved
Hide resolved
} | ||
|
||
// Prepare the context for the htmx request | ||
const context = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does htmx have a way of constructing its own request that we could use here? The answer could be "no"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated the signature of the function to make things easier to read. but, yes, no easy retry option with HTMX sadly
make sure the correct details are passed to retryHtmxRequest
…s easier to follow and read
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work @biyeun
Product Description
The time has come! We are officially including HTMX and Alpine in our JavaScript dependencies.
I didn't want to just drop these dependencies into HQ without some examples and documentation providing structure for how we want to use these libraries in our codebase. With such a large team, structure is immensely important. Hopefully, these examples and corresponding docs in the Styleguide will provide a good starting point for us!
Example 1: CrispyForms usage
This example uses Alpine to sprinkle interactivity into a Crispy Form—a very common use case for HQ. It also uses
HTMX to asynchronously load that form to a "host" view and process the response from that form.
view on staging (must be logged in)
Example 2: To-Do List
Taking inspiration from @snopoke's presentation at the GTD Summit, we have a simple To-Do list demoing the usage of
HtmxActionMixin
(explained in the technical summary). Additionally, this demos the usage of Alpine for a simple inline editing widget.view on staging (must be logged in)
(a demo of the HTMX request error modal can be triggered here as well!)
Styleguide documentation to visually link everything together for the demos!
Technical Summary
htmx
andalpine.js
as javascript dependenciesjs_entry
pointhqwebapp/js/htmx_and_alpine
that can be used on a page for folks to quickly get started with HTMX and Alpine without writing any additional javascript filesHqHtmxActionMixin
, which can be mixed into django template views so that HTMX requests to that view can process and return partial template responses via methods decorated with@hq_hx_action()
HqHtmxActionMixin
HqHtmxActionMixin
for form interactions with HTMX thatFormView
that processes HTMX requests and is hosted on a regular template view. Note, it's possible to also have that template view useHqHtmxActionMixin
for additional non-form HTMX activity for more complex usageAlpine.data()
) for more complex pagesHqHtmxDebugMixin
added for simulating server issues during development of views usingHqHtmxActionMixin
Safety Assurance
Safety story
Only introducing new dependencies and examples / documentation. Not affecting any active pages.
Automated test coverage
N/A
QA Plan
N/A
Rollback instructions
Labels & Review