Comments (6)
Hi Anthony,
I am working on an approach for exactly this. It is going to take me a bit to get it right, but I think you will be happy with the results. I will keep this issue open until I'm ready to discuss it.
from htmx.
@agraddy totally understand.
Your other options are a simple extension that handles the error.htmx error, or simply a javascript event handler on the body for the same event.
I'm trying to keep htmx as simple as possible and make it open and extensible for all the rest.
Should also mention that you can call out to javascript from a hyperscript handler:
<form hx-post="/ajax/contact" _="on error.htmx(errorInfo) call myJavascriptMethod(errorInfo)">
and just use hyperscript as the glue between the events and the javascript logic.
from htmx.
@agraddy here is a preview of what's coming in 0.1:
https://dev.htmx.org/docs/#hyperscript
from htmx.
Thanks for following up. That does appear to solve the issue. Having a new language isn't really appealing to me personally; I'd rather just write javascript. One of the initial draws of HTMX for me was its simplicity and that it wasn't trying to fully recreate javascript functionality in HTML. It handled the most important use case very efficiently and if needed, you could write your own extension.
I could see how a lot of people would find hyperscript appealing but it's just not for me. That being said, it does appear to solve the issue that I brought up so I believe this can be marked as solved (I'm not sure what your protocol is for closing issues - I don't want to prematurely close the issue since you had said you were keeping it open - I'll leave the status of the issue up to you).
Thanks!
from htmx.
Just for future reference for anybody finding this when searching for how to handle errors. I'm assuming the proposed solution for the scenario I originally gave is that you would write code like this (I'm not sure if this works but I believe this is the goal):
<form hx-post="/ajax/contact" _="on error.htmx(errorInfo) add errorInfo to .messages">
<div class="messages"></div>
<div>
<label>Name</label>
<input type="text" name="name" value="" />
</div>
<div>
<label>Email</label>
<input type="text" name="email" value="" />
</div>
<div>
<label>Message</label>
<textarea name="message"></textarea>
</div>
<div>
<input type="submit" value="Send" />
<span class="loading"></span>
</div>
</form>
from htmx.
One more comment before closing this issue is that you can simply have your server respond with a 200
status:
STATUS: 200
<p class="error">All fields are required.</p>
from htmx.
Related Issues (20)
- A way to reset/block hx-select and HX-Reselect. IMPROVEMENT
- (website) Images are not displayed in Atom feed
- Question about async encodeParameters in extension
- When using HX-Redirect, the htmx:afterRequest event's detail.successful and detail.failed fields are undefined
- Form doesn't reactivate again when receiving itself in Chrome HOT 3
- Behaviour when disconnected/unmounted from body
- HX-Location should respect Hx-Push-Url when false HOT 2
- htmx.ajax('DELETE') HOT 1
- Unable to understand why this works with html&js but not with htmx HOT 2
- Preserving Web Component state with `hx-preserve` on browser navigation HOT 1
- Adding attributes with loading-states extension
- hx-select conflict HOT 2
- [Question] Option to override xhr request with call to my SDK HOT 7
- [Question] 204 with hx-swap="delete" HOT 1
- hx-on is not working for custom events HOT 6
- hx-trigger from:<Extended CSS selector> breaks after target replaced
- Comma separated, multiple path-deps?
- Events htmx:afterRequest / htmx:afterOnLoad not fired in some cases
- Feature Request: http header HX-Redirect with value back HOT 1
- Improve documentation for websocket extension
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from htmx.