bigskysoftware / bigskysoftware/htmx

Htmx do not respect a updated form action on a boosted form updated by javascript before form.requestSubmit()

Open
#2,315 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
49.4k
Forks
1.7k
Avg merge
3d 22h
Merged PRs (30d)
30

Description

When I try to use hx-boosted to submit a form to sever,

Expected: the form to use the updated action1 path post to server
Actual: use the default empty path

I discover seems due to https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js#L1426,

the action path is getted when page init (thus the action is `""`).

Then https://github.com/bigskysoftware/htmx/blob/master/src/htmx.js#L3208 will update the path to docuemnt current url.

My workaround is call `htmx.process(form)` before `form.requsetSubmit()`

Is it an expected use case for calling `htmx.process` in this case?
if yes, maybe consider adding documentation in hx-boosted?

Simplified Problematic Version: (I do not know why cannot reproduce in codepen)
```html

document.addEventListener('DOMContentLoaded', function(e) {
htmx.logAll()
document.getElementById('btnRequestSubmit').addEventListener('click',requestSubmit)
})

function requestSubmit() {
const form = document.querySelector('form')
form.action = 'action1'
form.requestSubmit()
}

Button for requsetSubmit
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.