79344890

Date: 2025-01-10 07:28:49
Score: 0.5
Natty:
Report link

Thank you for all your effort. I found the answer: Use htmx:confirm instead of hx-on:submit:

<form id="assessment" name="assessment" 
    hx-post="/assessment-result.php"
    hx-target=".questions_list" 
    hx-swap="outerHTML transition:true swap:200ms" 
    hx-trigger="submit"
    hx-include=".questions_list input[type=radio]:checked">
...
</form>
document.body.addEventListener('htmx:confirm', (event) => {
        event.preventDefault();

        if( invalid ) {
            swal('Invalid form');
        }else{
            // https://htmx.org/events/#htmx:confirm
            // true to skip the built-in window.confirm()
            event.detail.issueRequest(true);
        }
});
Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Ellery Leung